views:

375

answers:

3

Hi,

I am new to the objective c coding in iPhone. i am using below code to animate the image for 40 seconds

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:40.0];
object.transform = CGAffineTransformMakeRotation(1.57);
[UIView commitAnimations];

i need to speed up the animation after 10 sec. i.e the animation should work with above values for 10sec, after that the animation speed should increase.

+2  A: 

You will not be able to do it with the

[UIView beginAnimations:nil context:nil];

construct. Have a look at the core animation framework:

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreAnimation%5Fguide/Articles/AnimatingLayers.html#//apple%5Fref/doc/uid/TP40006085-SW1

What you want to do is a serie of Keyed Animations if I remember correctly

MLefrancois
A: 

Try [UIView setAnimationCurve:]. UIViewAnimationCurveEaseIn may do it for you.

If you really need precise control--"x speed for 10 seconds, then y speed for 30 seconds"--the simplest way might be two animations, the second starting immediately after the first has finished. Set up a delegate to get a callback after the first animation has finished, and you can start a second animation immediately. (I've used this before to implement a "bounce" where a view animates up, then down.) May be easier than trying to do a whole keyframe animation.

jasoncrawford
A: 

You need to use Core Animation on the view layer instead of using the UIView animation proxy. CAKeyframeAnimation will enable you to create key frames for your animation and it enables you to specify key times (keyTimes property in the CAKeyframeAnimation class) that determine how much time it should take between key frames.

The trick there is that your first key frame will not be the end transform, but rather some intermediate value for the transform. Your final key frame will have your ending transform. You specify with the key time when the next key frame should begin. If your total duration is 40 seconds and you want the first change in speed to occur 10 seconds into the animation, you specify that change as your second key frame value and specify 0.25 as your key time assuming you wanted it to take a quarter of the full duration.

From the docs:

keyTimes

An optional array of NSNumber objects that define the duration of each keyframe segment.

@property(copy) NSArray *keyTimes

Discussion

Each value in the array is a floating point number between 0.0 and 1.0 and corresponds to one element in the values array. Each element in the keyTimes array defines the duration of the corresponding keyframe value as a fraction of the total duration of the animation. Each element value must be greater than, or equal to, the previous value.

The appropriate values in the keyTimes array are dependent on the calculationMode property.

If the calculationMode is set to kCAAnimationLinear, the first value in the array must be 0.0 and the last value must be 1.0. Values are interpolated between the specified keytimes.

If the calculationMode is set to kCAAnimationDiscrete, the first value in the array must be 0.0.

If the calculationMode is set to kCAAnimationPaced, the keyTimes array is ignored.

If the values in the keyTimes array are invalid or inappropriate for the calculationMode, the keyTimes array is ignored.

Best regards.

Matt Long