Simple Sprite Animation on iPhone
I am trying to do a si开发者_如何学Cmple animation on the iPhone and then have it stop once it is finished. The code I am currently using is:
NSArray *imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"init_lay1.png"],
[UIImage imageNamed:@"init_lay2.png"],
[UIImage imageNamed:@"init_lay3.png"],
[UIImage imageNamed:@"init_lay4.png"],
[UIImage imageNamed:@"init_lay5.png"],
[UIImage imageNamed:@"init_lay6.png"],
[UIImage imageNamed:@"init_lay7.png"],nil];
imageViewArms.animationImages = imageArray;
imageViewArms.animationDuration = 0.23;
imageViewArms.contentMode = UIViewContentModeBottomLeft;
imageViewArms.animationRepeatCount = 0.0;
[imageViewArms startAnimating];
I'm not sure of how to stop it once it is finished. Any ideas? Thanks.
To stop the animation once it is finished you should use:
imageViewArms.animationRepeatCount = 1;
not:
imageViewArms.animationRepeatCount = 0;
Setting the animationRepeatCount to 0 means that the animation wil be looped. Setting it to 1 means that it will be played only once.
-[UIImageView stopAnimating]?
精彩评论