Re: problems with CAAnimation
Re: problems with CAAnimation
- Subject: Re: problems with CAAnimation
- From: Memo Akten <email@hidden>
- Date: Thu, 19 Mar 2009 15:47:03 +0000
Hi Matt, thanks for the answer and yes you are right on both fronts:
- if I use fillMode and removeOnCompletion then it is visibly sticky,
BUT when I apply another animation (e.g. shrinkAnimation which scales
To:1, without setting a From value) then it snaps straight back to 1,
probably because internally the scale is still 1. If I set the From
value for my shrinkAnimation, then it works, BUT if I quickly trigger
grow followed by shrink, it first snaps upto the full hover scale, and
then animates down - which makes sense given the code, but is not the
desired behaviour. Ideally both my grow and shrink animations should
not have a From value, as I want them to simply animate To a specific
target from where it was at the time of animation being triggered
- Manually setting rootLayer setValue: forKeyPeth:@"transform.scale"
does work perfectly. However this was a simplified example, and
actually I have quite a few CAAnimationGroups, each with about 4-5
CABasicAnimations (scale, position, rotation, alpha etc.). So do I
really have to set the To Value for every property manually before
adding an animation group? And what key should I give the animation
group when adding?
Cheers,
Memo.
On 19 Mar 2009, at 15:31, Matt Long wrote:
Your layer's transform.scale knows nothing of the toValue in the
animation. You have to explicitly set it in the layer in addition to
animating it. This also means that you need to add the animation
using the correct keypath otherwise it will use the default
animation instead of yours. Change your code to do this:
[rootLayer setValue:[[[CardManager instance] config]
objectForKey:@"cardHoverScale"] forKeyPath:@"transform.scale"];
[rootLayer addAnimation:growAnimation forKey:@"transform.scale"];
Notice I've specified a keypath in the addAnimation: call. I haven't
actually tested this, by the way, but the basic idea is that you
have to set the value in the layer in order for it to stick. And you
have to specify the correct keypath or it won't use your animation
when it runs.
There is another way to make it sticky without actually changing the
layer's value. You explicitly set these two fields on the animation:
[growAnimation setFillMode:kCAFillModeForwards];
[growAnimation setRemovedOnCompletion:NO];
This will not cause the value in the layer to change, however, it
will give you the visible stickiness you seek.
Best Regards.
-Matt
On Mar 19, 2009, at 9:13 AM, Memo Akten wrote:
Hi, I posted this on the quartz list yesterday but received no
response, it seems like such a simple thing...
When I add an animation to my layer, it animates, but then snaps
back to its previous position. Is this normal?
growAnimation = [[CABasicAnimation
animationWithKeyPath:@"transform.scale"] retain];
growAnimation.duration = 0.25;
growAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
growAnimation.toValue = [[[CardManager instance] config]
objectForKey:@"cardHoverScale"];
growAnimation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[rootLayer addAnimation:growAnimation forKey:nil];
_______________________________________________
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