On Feb 23, 2010, at 6:45 AM, Gustavo Pizano wrote:

> //Create the layers of the buttons _moviesButton is one of the UIButtons
>       CALayer * moviesLayer = _moviesButton.layer;
>       moviesLayer.anchorPoint = CGPointMake(0.0f, 0.0f);
>       CAKeyframeAnimation * animatedButonsAnimation = [CAKeyframeAnimation 
> animationWithKeyPath:@"position"];
>       animatedButonsAnimation.duration = 0.4;
>       animatedButonsAnimation.delegate = self;
>       animatedButonsAnimation.path = moviPathRef;
>       animatedButonsAnimation.timingFunction=[CAMediaTimingFunction 
> functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
>       [moviesLayer addAnimation:animatedButonsAnimation 
> forKey:@"animateButton"];

As an FYI, using a CAKeyframeAnimation to move a layer from point A to point B 
is a bit of overkill. You can use a CABasicAnimation to do the same thing by 
using the to/from values. If you plan to make the transit path more complex, 
then a keyframe animation is perfectly fine however. If you aren't tied to 
using Core Animation directly however, you can do this even more simply using 
UIView's +beginAnimations:context: and +commitAnimations methods.

Additionally, rather than changing the anchorPoint do your animation based on 
the center of the view instead of it's frame's origin (which will also continue 
to work as you expect should you need to do an animation on a layer that has a 
transform).

> So, right now all works as expected, but the delegate method its being called 
> 5 times, once per animation,  which in fact Im reusing the one I created for 
> the movies Layer just with a different path and add it to a different button 
> layer.
> 
> I wanted then somehow to use CAAnimationGropu to store each CAKeyAnimation in 
> the array argument, and somehow just start the group animation, and my 
> delegate method will be called just once... is my theory right?
> 
> In that case, I can't not call the [<CALayer> 
> addAnimation:animatedButonsAnimation forKey:@"animateButton"]; otherwise the 
> animation will fire, so to what layer should I add the CAAnimationGroup? or 
> what shall I do?


Core Animation always copies an animation when you add it to a layer. Layers 
cannot share animations, and you cannot group animations across layers.

You will have to deal with getting called back multiple times (once per 
animation).
--
David Duncan
Apple DTS Animation and Printing

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to