开发者

Non-dirty view gets redrawn

开发者 https://www.devze.com 2023-04-09 06:35 出处:网络
I do have a strange problem. I programmed a a dockview. It\'s basically a NSView with three vertical subviews inside. So I have a left dock, a middle view and a right dock. Both docks are collapsable

I do have a strange problem. I programmed a a dockview.

It's basically a NSView with three vertical subviews inside. So I have a left dock, a middle view and a right dock. Both docks are collapsable. The middle view gets resized while collapsing.

I'm using CoreAnimation to animate the collapsing process. This works almost correct. If I uncollapse the left dock, the right docks drawRect method gets called although it's not dirty.

If I deactivate the animator and set the new frame size directly, the right dock not gets redrawn while uncollapsing so I assume the calculation of the frames is correct.

Here is my code for collapsing the docks:

- (void) mouseDown:(NSEvent *)event 
{
  // Exit method if already animating a dock
  if(is_animating)
  {
    return;
  }

  NSPoint firstPoint    = [self convertPoint:[event locationInWindow] fromView:nil];
  unsigned long divider = [self mousePointInCollapseRect:firstPoint];

  // If not clicked on a divider don't animate anything
  if(divider == NSNotFound)
  {
    return;
  }

  NSView* main_view     = [[self subviews] objectAtIndex:VIEW_MIDDLE];
  NSView* collapse_view = [[self subviews] objectAtIndex:(divider == 0)? VIEW_LEFT : VIEW_RIGHT];

  NSRect cframe = [collapse_view frame];  // New collapsable frame
  NSRect mframe = [main_view frame];      // New main frame

  if([self isSubviewCollapsed:collapse_view] == NO)
  {
    if(divider == 0)
    {            
      cframe.size.width  = 0.0;
      mframe.origin.x   -= (dock_width_left + DIVIDER_THICKNESS);
      mframe.size.width += (dock_width_left + DIVIDER_THICKNESS);
    }
    else
    {      
      mframe.size.width += (collapse_view.frame.size.width + DIVIDER_THICKNESS);
      cframe.size.width  = 0.0;
      cframe.origin.x    = mframe.origin.x + mframe.size.width;
    }

    // Turn off autoresizesSubviews on the collapsible subview
    [collapse_view setAutoresizesSubviews:NO];

    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:(ANIMATION_DURATION)]; 

    [[collapse_view animator] setFrame:cframe];
    [[main_view animator]     setFrame:mframe];

    [NSAnimationContext endGrouping];
  }
  else
  {
    // Uncollapse dock    
    if(divider == 0)
    {
      // Left dock
      cframe.size.width  = dock_width_left;
      mframe.origin.x    = (COLLAPSEBAR_THICKNESS + dock_width_left + DIVIDER_THICKNESS);
      mframe.size.width -= (dock_width_left + DIVIDER_THICKNESS);
    }
    else
    {   
      // Right dock
      mframe.size.width -= (dock_width_right + DIVIDER_THICKNESS);
      cframe.size.width  = dock_width_right;
      cframe.origin.x    = mframe.origin.x + mframe.size.width + DIVIDER_THICKNESS;
    }

    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:ANIMATION_DURATION];   

    [[main_view animator]     setFrame:mframe];
    [[collapse_view animator] setFrame:cframe];

    [NSAnimationContext endGrouping];

    //Restore Autoresizing on subview
    [self performSelector:@selector(restoreAutoResizingOfSubview:) withObject:collapse_view afterDelay:ANIMATION_DURATION + 0.05];
  }

  is_animating = YES;
  [self performSelector:@selector(animationEnded) withObject:nil afterDelay:ANIMATION_DURATIO开发者_如何学JAVAN + 0.05];
}

So why gets a non-dirty view redrawn?

0

精彩评论

暂无评论...
验证码 换一张
取 消