Re: Animated split view collapsing
Re: Animated split view collapsing
- Subject: Re: Animated split view collapsing
- From: "Lawrence Sanbourne" <email@hidden>
- Date: Thu, 4 May 2006 10:40:35 -0500
On 5/1/06, Paul Kim <email@hidden> wrote:
Hi Larry,
I think the problem is that you need to resize both views in the
animation. Have one view collapse while the other expands. In
addition, since the animation will set the view to "hidden" when it
collapses it, you need to unhide it when expanding it back out (I
think this is what causes your view to disappear).
The code below is more specific to my case where only one of the two
views is uncollapsed at any one time but it demonstrates how to do
the animation. In conjunction with the display call in the delegate
method, it works for me. I left out the horizontal case for brevity.
Also, I don't hide the splitter (I think you asked for that
originally?) but you should be able to adapt it from here.
Paul,
Thank you so much! That was tremendously helpful. I cleaned up my code
based on yours, and the animation is working. It's fairly jerky, but I
think I might have to be satisfied now. My code is below, if anyone
wants to use it or try to explain the jerkiness.
Larry
/*! Unhides both subviews and changes the splitter position, possibly
with animation. This method's behavior is undefined if there are not
exactly two subviews. Note that the delegate must call
-setNeedsDisplay:YES whenever -isSplitterAnimating returns YES.
Reference: Paul Kim <email@hidden>.
*/
- (void)setSplitterPosition:(float)newSplitterPosition animate:(BOOL)animate {
if ([[self subviews] count] < 2)
return;
NSView *subview0 = [[self subviews] objectAtIndex:0];
NSView *subview1 = [[self subviews] objectAtIndex:1];
NSRect subview0EndFrame = [subview0 frame];
NSRect subview1EndFrame = [subview1 frame];
if ([self isVertical]) {
subview0EndFrame.size.width = newSplitterPosition;
subview1EndFrame.origin.x = newSplitterPosition + [self dividerThickness];
subview1EndFrame.size.width = [self frame].size.width -
subview0EndFrame.size.width - [self dividerThickness];
} else {
subview0EndFrame.size.height = newSplitterPosition;
subview1EndFrame.origin.y = newSplitterPosition + [self dividerThickness];
subview1EndFrame.size.height = [self frame].size.height -
subview0EndFrame.size.height - [self dividerThickness];
}
// Be sure the subview isn't hidden from a previous animation.
[subview0 setHidden:NO];
[subview1 setHidden:NO];
// Update subviewEndFrame.origin so that the frame is positioned
if (animate) {
NSDictionary *subview0Animation = [NSDictionary dictionaryWithObjectsAndKeys:
subview0, NSViewAnimationTargetKey,
[NSValue valueWithRect:subview0EndFrame], NSViewAnimationEndFrameKey, nil];
NSDictionary *subview1Animation = [NSDictionary dictionaryWithObjectsAndKeys:
subview1, NSViewAnimationTargetKey,
[NSValue valueWithRect:subview1EndFrame], NSViewAnimationEndFrameKey, nil];
NSViewAnimation *animation = [[NSViewAnimation alloc]
initWithViewAnimations:[NSArray arrayWithObjects:subview0Animation,
subview1Animation, nil]];
[animation setAnimationBlockingMode:NSAnimationBlocking];
[animation setDuration:0.3];
// Use default animation curve, NSAnimationEaseInOut.
isSplitterAnimating = YES;
[animation startAnimation];
isSplitterAnimating = NO;
[animation release];
} else {
[subview0 setFrame:subview0EndFrame];
[subview1 setFrame:subview1EndFrame];
}
[self adjustSubviews];
}
/*! Only works with two subviews.
*/
- (float)splitterPosition {
if ([self isVertical])
return [self frame].size.width - [[[self subviews] objectAtIndex:0]
frame].size.width;
else
return [self frame].size.height - [[[self subviews] objectAtIndex:0]
frame].size.height;
}
- (BOOL)isSplitterAnimating {
return isSplitterAnimating;
}
///////////// NSSplitView delegate
- (void)splitView:(NSSplitView *)sender
resizeSubviewsWithOldSize:(NSSize)oldSize {
// Don't interfere with animation.
if ([sender isSplitterAnimating]) {
// I got infinite recursion when I used plain old -display.
[sender setNeedsDisplay:YES];
return;
}
// Do whatever else you want to do in this delegate.
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden