UIImageView animateImages Delay
I'm kind of stuck with this problem. I have a UIImageView animation with 37 images where I show a glass filling with alcohol. I initialize my image array in ViewDidLoad,
NSArray * GlassAnim = [[NSArray alloc] initWithObjects:
[UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"SodaPour1" ofType:@"png"]],
[UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"SodaPour39" ofType:@"png"]],
开发者_JAVA技巧 nil];
imgGlass.animationImages = GlassAnim;
imgGlass.animationDuration = 2.5;
imgGlass.contentMode = UIViewContentModeScaleAspectFit;
imgGlass.animationRepeatCount=1;
[GlassAnim release];
Then I call startAnimating when user taps the screen. But the problem is that the animation has a half a second delay for the first time. Each image has a dimension of 330*372 pixels and the file size is 180KB png files. Is there a better way to do this other than playing a video?.
Thanks.
Here you go,
You start a Timer to change image names.
timerAnimation = [[NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(changeImagesAccordingly) userInfo:nil repeats:YES] retain];
Rename the images in a sequence. I have 16 images.
Eg:- "AnimationImg1.png", "AnimationImg2.png", "AnimationImg3.png"
- (void)changeImagesAccordingly { if (iImgAnim<16) { imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"AnimationImg%d",iImgAnim] ofType:@"png"]]; iImgAnim++; } else { [timerAnimation invalidate]; iImgAnim=1; } }
That should do it :)
精彩评论