Re: Resizing NSView with CABasicAnimation
Re: Resizing NSView with CABasicAnimation
- Subject: Re: Resizing NSView with CABasicAnimation
- From: Bill Dudney <email@hidden>
- Date: Wed, 16 Apr 2008 09:51:09 -0600
Hi Michael,
My pleasure. Although Scott wrote the docs that I used to learn CA so
I could write a book ;)
As Scott pointed out if you are simply resizing the view you don't
necessarily need layers to accomplish animation as the view's animator
will do the animation just fine. If you are doing other stuff that
requires a layer then ignore this comment.
So to get chained animations I would suggest an animation group (added
to the view, not the layer) something like this (stream of
consciousness code here so YMMV);
ani1 = [CABasicAnimation animationWithKeyPath:@"frameSize"];
ani1.duration = 1.0f;
ani2 = [CABasicAnimation animatoinWithKeyPath:@"alphaValue"];
ani2.beginTime = 1.0f;
ani2.duration = 1.0f;
ani2.toValue = 0.5f;
myGroup.animations = [NSArray arrayWithObjects:ani1, ani2, nil];
myGroup.duration = 2.0f;
myView.animations = [NSDict dictWithObj:myGroup forKey:@"frameSize"];
now when you tweak the frameSize of myView like thus;
myView.frameSize = newSize;
your group animation will fire. The frameSize animation will run for 1
second fromt he old size to the new size and the alphaValue animation
will run starting at 1 second and willr un for one second.
Only reason that a layer is required for this is the opacity, if you
are animating something that does not require a layer then you could
do the same thing without layers in the picture at all.
HTH,
-bd-
http://bill.dudney.net/roller/objc
On Apr 16, 2008, at 7:43 AM, Michael Fey wrote:
Bill,
Given that you've "written the book" on Core Animation, I really
appreciate your insights. Since my view is layer backed (I called
setWantsLayer:YES on a parent view), then my call to [[self layer]
addAnimation...] should be [self addAnimation] instead? The other
thing that I'm not sure about is the NSString values that I'm
passing in for animationWithKeyPath: and addAnimation:forKey:. Do
those look correct for resizing the view?
Scott,
Your suggesstion to do away with the explicit animation is a good
one, so let me explain my reasons for using it: I am trying to
chain together a series of animations and I don't want one to happen
before the previous one has finished. By using a CABasicAnimation I
can specify a delegate (in this case my NSView subclass) that has
the animationDidStart and animationDidEnd methods. Using these
delegate methods I intended to control the series of animations. If
there is a better way of waiting for one animation to finish before
starting another one I am all ears, especially if I can do it with
implicit animations.
Thanks to both of you,
Michael
On Apr 16, 2008, at 1:02 AM, Scott Anguish wrote:
On Apr 15, 2008, at 11:01 PM, Bill Dudney wrote:
Hi Michael,
Are you layer backed or layer hosting (i.e. did you se the layer
explicitly?) If you are layer hosting then add he explicit
animation to the view instead of the layer (when layer backing you
should not manipulate the layer directly).
I don't think it matters. If he's trying to resize the view, the
layers aren't relevant. this can be done trivially through the
view's animator with or without layer backing/layer hosting/ being
on.
If you are doing layer hosting then try leaving the 'from' and
'to' values out.
_______________________________________________
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