Re: Animating NSSplitView collapse/uncollapse
Re: Animating NSSplitView collapse/uncollapse
- Subject: Re: Animating NSSplitView collapse/uncollapse
- From: Alvaro Costa Neto <email@hidden>
- Date: Sun, 05 Feb 2012 19:58:34 -0200
Hey Luc, how are you?
I had to implement this exact functionality in a commercial project and here is what I've found:
- The delegate methods will be called when the animation occurs---continuously. So, if you are limiting the size of one of the subviews via "splitView:min/max...", this is going to cause you problems. My solution to this was to nil the delegate in the NSSplitView subclass before starting the animations and, when the animations finish, get it back to the original value. Just remember: if you start animating both view's frames, the "animationDidFinish" delegate methods will be called twice, once for each subview on both sides of the divider;
- The springs and struts mechanism goes bananas when the views' sizes become zero. That's probably why your subviews are getting broken when you uncollapse: when you did collapse, any subviews from the collapsing view that has the resize-with-superview spring/struts will become zero sized, and when the uncollapse happens the mechanism will not function properly. One way to solve this is to make sure that you turn off all the spring/struts properties of your collapsing view's subviews before doing the animation and getting it back to normal after uncollapsing. This way, their sizes will not get zeroed;
- If the uncollapsing view is not getting back to the original size, it's most probably the first problem I explained earlier: delegate.
I hope this helps. Best regards,
Alvaro Costa Neto
Em 05/02/2012, às 18:59, Luc Van Bogaert escreveu:
> I've been trying to implement a splitview with animated collapse/uncollapse of one of its subviews. So far without success, although I think I'm very close to a working solution. There's a lot of documentation and sample code on the internet, but none of what I have found seems to fit my needs.
>
> Currently, this is the code that does the animation (in a NSSplitView subclass) :
>
> - (void)animateDividerToPosition:(CGFloat)dividerPosition
> {
> NSView *view0 = [[self subviews] objectAtIndex:0];
> NSView *view1 = [[self subviews] objectAtIndex:1];
> NSRect view0Rect = [view0 frame];
> NSRect view1Rect = [view1 frame];
> NSRect overalRect = [self frame];
> CGFloat dividerThickness = [self dividerThickness];
>
> if ([self isVertical]) {
> view0Rect.size.width = dividerPosition;
> view1Rect.origin.x = dividerPosition + dividerThickness;
> view1Rect.size.width = overalRect.size.width - view0Rect.size.width - dividerThickness;
> } else {
> view0Rect.size.height = dividerPosition;
> view1Rect.origin.y = dividerPosition + dividerThickness;
> view1Rect.size.height = overalRect.size.height - view0Rect.size.height - dividerThickness;
> }
>
> [NSAnimationContext beginGrouping];
> [[NSAnimationContext currentContext] setDuration:0.3];
> [[view0 animator] setFrame: view0Rect];
> [[view1 animator] setFrame: view1Rect];
> [NSAnimationContext endGrouping];
> }
>
> Collapse seems to work fine this way, but when I uncollapse a subview, the views contents are only drawn partially, similar to the effect one sees when the splitview delegate does not implement the methods to constrain the subview size.
>
> Any ideas?
> Thanks
>
> --
> Luc Van Bogaert
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden