Re: Animated NSSplitView headache
Re: Animated NSSplitView headache
- Subject: Re: Animated NSSplitView headache
- From: Luc Van Bogaert <email@hidden>
- Date: Sun, 12 Feb 2012 12:42:43 +0100
On 10 Feb 2012, at 14:21, Alvaro Costa Neto wrote:
> When the user drags the divider and collapses it, the split view retains the view's frames before the collapse and that's probably something that is giving you some problems. In this sense, there are two different behaviors going on when a collapse happen:
>
> 1) If the user drags the divider and collapses the subview, it's size will have the minimum allowed width/height and it's hidden property will become "TRUE";
>
> 2) If an animated collapse happens, the subview's frame will have zero width/height and it's hidden property will be also "TRUE" because you are hiding it when the collapse animation finishes.
>
> To detect when the split view has manually collapsed one of it's subviews, watch via KVO the subview's "hidden" property. When it changes to "TRUE" and the subview's frame is not zero sized, it means the user collapsed by dragging the divider. If it becomes true and the subview's frame is zero sized, it means the collapse animation has finished.
>
> One probable cause of headache is the uncollapse algorithm: before doing the uncollapse, always make sure that the collapsed subview's frame has zero width/height. This may not be true if the user has manually dragged the divider and collapsed the subview.
>
> To finish it up, only reenable the autosize mechanisms when the subview has finished uncollapsing. This will prevent the autosize algorithms from calculating negative sized frames.
>
Hey Alvaro,
Finally, success!
My implementation had already taken into account the explanations above (albeit without using KVO), but still without success. After many more frustrating hours trying to get this right, I finally decided the problem could be caused by some kind of timing issue (after all, the problem only manifested itself intermittently), and sure enough: after I had put the post animation stuff (ea. restoring subview autoresize, notifying observers, etc) in a separate method, and called this method with [self performSelector: withObject: afterDelay:] it now works as it should.
So, this is part of the implementation:
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.25f];
[[NSAnimationContext currentContext] setCompletionHandler:^(void) {
[self performSelector:@selector(postAnimation) withObject:self afterDelay:0.1f];
}];
[[NSNotificationCenter defaultCenter] postNotificationName:DSSplitViewWillToggleSubviewNotification object:self];
[[view0 animator] setFrame: view0Rect];
[[view1 animator] setFrame: view1Rect];
[NSAnimationContext endGrouping];
So I'm a very happy camper at the moment. Thanks for your help with this!
PS: as it turns out, there doesn't seem to be a need to temporarily disable my split view delegate during animation. It all comes down to correctly disabling and re-enabling autoresize, but the latter *after* the animation has completely finished.
--
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