How to control animation speed?
I'm moving an image and then expanding the image. The problem is my image is moving way to fast. Is there a way to to allow 2 animations to run and to control the speed? Here is the code:
- (IBAction)pushmove {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDurat开发者_开发问答ion:2.5];
square.transform = CGAffineTransformMakeTranslation(-200,-300);
[UIView setAnimationDuration:1.5];
square.transform = CGAffineTransformMakeScale(8,8);
[UIView commitAnimations];
Yes!
It's possible and fairly straightforward. The key thing is thatCAAnimation
implements theCAMediaTiming
protocol. So either on theCAAnimation
orCAAnimationGroup
you can set the speed as follows:
myAnimationGroup.speed = 2;
So if duration is4
, your group will execute in2
seconds.
Some of Apple's videos are very helpful on this subject. WWDC 2010 Session 424 coversCAMediaTiming
and it's uses. Checkout 46:30 seconds into the video.
Here's the link: WWDC 2010 Sessions
精彩评论