small medium large xlarge

06 Feb 2009, 16:26
Sean Rich (5 posts)

Great book, Bill. I enjoyed it. I have an app where I’m trying to use a split view that expands/collapses with a button (Coda by Panic is a good example of this). After making the split view layer-backed, I tried setting the subview’s frame to 0. When this is done with NSViewAnimation, you get a nice transition of the divider moving up and down as the subview is toggled, and I’m trying to achieve the same effect with Core Animation. With CA, I get a fade out effect that doesn’t look quite right. I’ve searched long and hard on this one, but I can’t find a way to make the animation look like a movement of the divider in the split view rather than a fade-out of the subview. Trivial code below. Thanks for your help.


    NSRect newFrame = [splitLeftView frame];
    newFrame.size.width = 0;
    [[splitLeftView animator] setFrame:newFrame];
07 Feb 2009, 07:42
Sean Rich (5 posts)

Sorry to reply to my own post, but I’ve made some progress on this issue. If you leave layer-backing off, CA animates the frame movement and doesn’t fade the subviews out and back in. Great! 2 problems, though: 1) I may need the subviews (or possibly a superview) to be layer-backed for other purposes. This means I still have to tackle the “fading out while animating frame movement” issue. Any ideas? 2) I need to know when the animation is complete. I can make one of my classes the delegate for the animation, but how do you do this for default animations? I tried (with and without layer-backing turned on) to get a reference to the animation using -animationForKey:@”frame” and +defaultAnimationForKey:@”frame” but got nil on both counts. I guess I could create an entirely new CABasicAnimation and assign it to the view with a key of “frame” but it seems like there must be an easier way just to get notified of the animation completing.

I put a sample project that demonstrates what I’m talking about at:


07 Feb 2009, 13:28
Bill Dudney (916 posts)

Hi Sean,

Glad you are making progress!

The frame property is not animated by its self, I believe the two animations that are used are for ‘frameOrigin’ and ‘frameSize’. You should be able to get a handle on the animations with these keys, however I think (but don’t remember for sure) that a new animation is created each time so you will likely have to create and attach your own animations.

I believe the fade out is happening because of the zero width frame. I think that the animator is looking at that and saying ‘hey this is going to be invisible so I need to fade it out’.

Can you instead use the;

  • (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex


Call it against the animator of the split view and it should work (I’ve not tried it tho).

Let us know when you get it worked out.

07 Feb 2009, 19:27
Sean Rich (5 posts)

Thanks for your reply, Bill. I haven’t cracked this nut yet, but I’ve found some interesting things: You’re right about using ‘frameOrigin’ and ‘frameSize’ although Apple’s Leopard release notes: lists ‘frame’ as a default animation parameter along with frameSize and frameOrigin.

Here’s the interesting stuff. If my controller calls: [[myView animationForKey:@”frameSize”] setDelegate:self]; in the awakeFromNib method, I get delegate callbacks for myView as expected, but I also get a callback for the other animations. For example, I have two subviews in a splitView, and I am animating the frames of both subviews. If I pass the bottomView in place of ‘myView’ in the snippet above, I also get delegate callbacks for the topView. Then I tried passing the splitView itself in place of ‘myView’, and I still got delegate callbacks for both subviews. I pushed the limit on this by passing the window’s contentView, a button not in the hierarchy of the splitView, and even a button residing on a different window - all attempts gave me delegate callbacks for both subviews. This seems odd to me since I don’t necessarily want to hear about every animation going on - just the one specified.

Looking to solve the fading tableview problem, I also tried using a tableview (inside a scrollview) not contained in a splitview. If I set frame width/height to zero, I don’t get the fade-out effect. Also tried changing the origin. Both animations were smooth. The fade-out only occurs when the tableview is inside a splitview. I tried setting the tableview’s ‘alphaValue’ animation to nil - didn’t work. I tried using my own CABasicAnimation for the framesize animation, but the tableview still fades out while the frame moves and fades back in once it’s complete. If I use a custom view instead of a tableview (it just fills the view with a color) then the fade-out doesn’t occur, so it doesn’t seem like the effect is forced by the splitview. (Side note: using CA on this custom view wasn’t a smooth animation - it flashed as it resized).

I tried the -setPosition:ofDividerAtIndex: but this isn’t a supported property. The divider jumps straight into place.

I’m running out of ideas on this one - has anyone solved this?

13 Jan 2010, 05:32
Allan Bazinet (1 post)

Old topic, but I ran into this problem today and thought I might post a comment regarding receiving unexpected callbacks as described above.

The issue seems to be that multiple views happen to be sharing the animation, so you’re seeing all of them in the animationDidStop:finished callback, rather than just the view you’re interested in.

This can be resolved by first making a copy of the animation, as in the following, so you’re certain that it’s not being shared.

NSString * key = @"frameSize";
CAAnimation * animation = [[myView animationForKey:key] copy];
[animation setDelegate:self];
[myView setAnimations:[NSDictionary dictionaryWithObject:animation forKey:key]];
29 May 2010, 05:57
Richard Smiley (23 posts)

Following up on Bill Dudney’s last post in this topic: Apple recently revised Technical Q&A QA1620 | Animating the frame of a CALayer.

The Apple note says roughly what Bill said about animating frame properties. (Perhaps he is the one who revised it, as part of his new job at Apple. ;-) The code apparently was updated from the original, 2008 version of the note. The parameter names differ from the ones Bill used. I don’t know whether that was the [only] change.

You must be logged in to comment