TWcode
TWcode

Reputation: 823

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 setAnimationDuration:2.5];
    square.transform = CGAffineTransformMakeTranslation(-200,-300);
    [UIView setAnimationDuration:1.5];
    square.transform = CGAffineTransformMakeScale(8,8);
    [UIView commitAnimations];

Upvotes: 0

Views: 326

Answers (1)

Max MacLeod
Max MacLeod

Reputation: 26682

Yes!

It's possible and fairly straightforward. The key thing is thatCAAnimationimplements theCAMediaTimingprotocol. So either on theCAAnimationorCAAnimationGroupyou can set the speed as follows:

myAnimationGroup.speed = 2;

So if duration is4, your group will execute in2seconds.

Some of Apple's videos are very helpful on this subject. WWDC 2010 Session 424 coversCAMediaTimingand it's uses. Checkout 46:30 seconds into the video.

Here's the link: WWDC 2010 Sessions

Upvotes: 1

Related Questions