Re: problems with CAAnimation
Re: problems with CAAnimation
- Subject: Re: problems with CAAnimation
- From: Memo Akten <email@hidden>
- Date: Thu, 19 Mar 2009 17:09:34 +0000
Hi Matt, yea it is a bit complex, but it seems to me that what I am
trying to do is actually quite simple:
- when I rollover a layer, it animates position, scale, rotation and
alpha.
- when I rollout, it animates back.
- if I rollover, then midanimation, rollout again, it should animate
back to original position *from where it was at the moment I rolled
out*, NOT snapping to the hover position (which is why I can't use
FromValues).
I also would like the animation to be EaseInEaseOut and know when the
animation is complete - which is why I'm using CAAnimation, so I can
use delegate - instead of using implicit animation.
Going back to what you were saying, I'm afraid I don't full
understand. So I extend CALayer? How would I use animationForKey? Does
that not only return the animation for a given arbitrary key?
Also I tried the code below, and unfortunately the animation happened
very quickly, not 5 seconds at all...
growAnimation = [[CABasicAnimation
animationWithKeyPath:@"transform.scale"] retain];
growAnimation.duration = 5; // very slow
growAnimation.toValue = [[[CardManager instance] config]
objectForKey:@"cardHoverScale"];
growAnimation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[rootLayer setValue:[[[CardManager instance] config]
objectForKey:@"cardHoverScale"] forKeyPath:@"transform.scale"];
[rootLayer addAnimation:growAnimation forKey:@"transform.scale"];
On 19 Mar 2009, at 17:01, Matt Long wrote:
Ok. You've just raised the bar! ;-) Seems that you would have to
specify the key path you're wanting for each animation which leads
me to think you won't be able to use grouping as you envision as
setAnimations on the CAAnimationGroup only takes an array rather
than a dictionary in which you could specify keypaths.
In all likelihood you'll have to use - (CAAnimation
*)animationForKey:(NSString *)key in a derived layer. Then you can
specify the animation you want for all keys you're interested in.
In answer to your last question, yes you will need to set the values
of all of the properties you're looking to animate, but if you
create a derived layer as I suggested and override animationForKey,
whenever those keypaths are changed, it will use the animation
you've specified so all you'll have to do is call
setValue:forKeyPath on the derived layer and it will use the correct
animation. Does that make sense?
-Matt
On Mar 19, 2009, at 9:47 AM, Memo Akten wrote:
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.
_______________________________________________
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