views:

205

answers:

2

I am creating a basic animation for my iPhone app. I have a choice to make between 2 different types of animation. I can use this...

NSArray *myImages = [NSArray arrayWithObjects: 
[UIImage imageNamed:@"myImage1.png"], 
[UIImage imageNamed:@"myImage2.png"], 
[UIImage imageNamed:@"myImage3.png"], 
[UIImage imageNamed:@"myImage4.gif"], nil]; 

UIImageView *myAnimatedView = [UIImageView alloc]; 
[myAnimatedView initWithFrame:[self bounds]]; 
myAnimatedView.animationImages = myImages; 
myAnimatedView.animationDuration = 0.25;  
[self addSubview:myAnimatedView]; 
[myAnimatedView release];

or something like this...

    [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.5];
 // other animations goes here
 myImage.transform = CGAffineTransformMakeRotation(M_PI*0.5);
 // other animations goes here
 [UIView commitAnimations];

I have quite a few of these parts to animate so I want to choose an option which uses the least amount of memory and runds the quickest. Any advice would be great, thanks

A: 

There are a lot of variables to account for in your question. Much of it will depend on the size and complexity of the images and the frequency with which the animation will run. My hunch is using the API provided transform will be the cheapest but the only real way to tell will be to stress test both animations and see which holds up the best in your case.

Robert maefs
Thanks for the heads up that's really useful. Would you think that using a small png and tiling it would be preferable to using a larger single png?
A: 

I would go hybrid: Generate your still images from the animation code and save the layer off to CGImages.

Peter