Reputation: 41
I create a 5-frame animation on UImageView and each image is created by [UIImage imageWithContentOfFile:xxx], however, the animation on simulator is working well but not on device, it usually has ~1 sec delay though the animation duration is 1sec.
This is my code.
NSArray *animations = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"ShakeAnimation"];
UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:[animations objectAtIndex:0]]];
imgView.tag = 10;
NSMutableArray *animationImgs = [[NSMutableArray alloc] init];
for( NSString *path in animations )
{
[animationImgs addObject:[UIImage imageWithContentsOfFile:path]];
}
[imgView setAnimationRepeatCount:2];
[imgView setAnimationImages:animationImgs];
[imgView setAnimationDuration:1];
[animationImgs release];
and when the view controller recieved shack event, it calls [imgView startAnimation];
Is anyway to preload the images involved in the animation? thanks.
Upvotes: 1
Views: 1437
Reputation: 41
I figured it out!
If you want to preload the UIImageView
animation images, just call [imgView startAnimating]
after initialization. It seemed to work for me.
Upvotes: 1