Re: Animated split view collapsing
Re: Animated split view collapsing
- Subject: Re: Animated split view collapsing
- From: "Greg Herlihy" <email@hidden>
- Date: Fri, 28 Apr 2006 00:01:35 -0700
Changing the animation curve for an NSViewAnimation produces strange
results, so I would not call setAnimationCurve at all on the animation
object. Instead, I would just vary the dimensions of the rectangle specified
by NSViewAnimationEndFrameKey (that is, when closing the target view,
specify the small rectangle, when opening, use the larger one).
Greg
----- Original Message -----
From: "Lawrence Sanbourne" <email@hidden>
To: <email@hidden>; <email@hidden>; <email@hidden>
Cc: <email@hidden>
Sent: Thursday, April 27, 2006 8:01 AM
Subject: Re: Animated split view collapsing
Here's the current version of my animated split view hiding code. It's
working beautifully for collapsing the view. However, it displays the
window background and jumps to the endFrame position when
un-collapsing. Also, if the window or superview has been resized, it
does nothing except resize the elements inside the split pane to
strange sizes.
I'm wondering if I'm getting interference from my delegate methods.
I've pasted them below, in case anyone wouldn't mind taking a look at
them.
Thanks again, everyone, for the help you've already given.
Larry
// NSSplitView animated collapsing (in MySplitView : NSSplitView class)
- (void)setFrame:(NSRect)endFrame forSubview:(NSView *)subview
animate:(BOOL)animate {
if (animate) {
NSDictionary *windowResize = [NSDictionary
dictionaryWithObjectsAndKeys:subview, NSViewAnimationTargetKey,
[NSValue valueWithRect:endFrame], NSViewAnimationEndFrameKey, nil];
NSViewAnimation *animation = [[NSViewAnimation alloc]
initWithViewAnimations:[NSArray arrayWithObject:windowResize]];
[animation setAnimationBlockingMode:NSAnimationBlocking];
[animation setDuration:0.25];
if ([self isVertical] && endFrame.size.width > [subview frame].size.width ||
![self isVertical] && endFrame.size.height > [subview frame].size.height) {
// The subview is small and we need to enlarge it.
[animation setAnimationCurve:NSAnimationEaseIn];
} else if ([self isVertical] && endFrame.size.width < [subview
frame].size.width ||
![self isVertical] && endFrame.size.height < [subview frame].size.height) {
// The subview is large and we need to shrink it.
[animation setAnimationCurve:NSAnimationEaseOut];
} else {
NSLog(@"Unable to determine animation direction.");
[animation setAnimationCurve: NSAnimationEaseInOut];
}
[animation setAnimationCurve:NSAnimationEaseIn];
[animation startAnimation];
[animation release];
} else {
[subview setFrame:endFrame];
[self adjustSubviews];
}
[self setNeedsDisplay:YES];
}
///////////////////////////
// Delegate methods (in NSWindowController subclass)
// Note: In my setup, verticalSplitView encloses the sourceInfoSplitView.
- (float)splitView:(NSSplitView *)sender
constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset {
//NSLog(@"splitView:%@ constrainMaxCoordinate:%f ofSubviewAt:%d",
sender, proposedMax, offset);
if (sender == verticalSplitView) {
// Less than half the minimum window width.
return [[self window] minSize].width / 2.1;
} else if (sender == sourceInfoSplitView) {
return proposedMax - MaximumSourceBezelHeight;
} else {
return proposedMax;
}
}
- (float)splitView:(NSSplitView *)sender
constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset {
//NSLog(@"splitView:%@ constrainMinCoordinate:%f ofSubviewAt:%d",
sender, proposedMin, offset);
if (sender == sourceInfoSplitView) {
return MinimumSourceBezelHeight;
} else if (sender == verticalSplitView) {
return MinimumLeftColumnWidth;
} else {
return proposedMin;
}
}
- (void)splitView:(MySplitView *)sender
resizeSubviewsWithOldSize:(NSSize)oldSize {
//NSLog(@"splitView:%@ resizeSubviewsWithOldSize:%@", sender,
NSStringFromSize(oldSize));
[sender adjustSubviews];
if (sender == sourceInfoSplitView) {
NSView *topSubview = [[sender subviews] objectAtIndex:0];
NSView *bottomSubview = [[sender subviews] objectAtIndex:1];
NSRect topFrame = [topSubview frame];
NSRect bottomFrame = [bottomSubview frame];
// Bottom frame (info view) height stays fixed.
NSArray *subviewFramesBeforeResize = [sender subviewFramesBeforeResize];
if ([subviewFramesBeforeResize count] > 0)
bottomFrame.size.height = [[subviewFramesBeforeResize
objectAtIndex:1] rectValue].size.height;
// Top frame (Source table) height is flexible.
topFrame.size.height = [sender frame].size.height - [sender
dividerThickness];
if (![sender isSubviewCollapsed:bottomSubview])
topFrame.size.height -= bottomFrame.size.height;
if (topFrame.size.height < MinimumSourceBezelHeight) {
// Resize bottom frame to match. Minimum window size should allow enough
room
// to do this.
topFrame.size.height = MinimumSourceBezelHeight;
bottomFrame.size.height = [sender frame].size.height - [sender
dividerThickness] - topFrame.size.height;
}
[topSubview setFrame:topFrame];
[bottomSubview setFrame:bottomFrame];
[topSubview setNeedsDisplay:YES];
[bottomSubview setNeedsDisplay:YES];
} else if (sender == verticalSplitView) {
NSView *leftSubview = [[sender subviews] objectAtIndex:0];
NSView *rightSubview = [[sender subviews] objectAtIndex:1];
NSRect leftFrame = [leftSubview frame];
NSRect rightFrame = [rightSubview frame];
// Left column stays fixed.
NSArray *subviewFramesBeforeResize = [sender subviewFramesBeforeResize];
if ([subviewFramesBeforeResize count] > 0)
leftFrame.size.width = [[subviewFramesBeforeResize objectAtIndex:0]
rectValue].size.width;
// Right column (table view or widget matrix) is flexible.
rightFrame.size.width = [sender frame].size.width - [sender
dividerThickness];
if (![sender isSubviewCollapsed:leftSubview])
rightFrame.size.width -= leftFrame.size.width;
[leftSubview setFrame:leftFrame];
[rightSubview setFrame:rightFrame];
[leftSubview setNeedsDisplay:YES];
[rightSubview setNeedsDisplay:YES];
}
}
_______________________________________________
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