简体   繁体   中英

How to prevent UIImage from continually replaying an animation

I am making a game and currently my "player" is animating as I've implemented (which is wrong at the moment) and it continually runs the animation from start to start because it always restarts from the beginning when the function is called. What is the best way to prevent this and let the animation run all the way through? Here is the code I'm using at the moment:

- (void) startAnimatingLeft
{

NSArray *images = [NSArray arrayWithObjects:img9,img10,img11,img12,img13,img14,img15,img16, nil];

[imageView setAnimationImages:images];

[imageView startAnimating];
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(nothingMovingLeft) userInfo:nil repeats:NO];
}

From UIImage documentation :

startAnimating

This method always starts the animation from the first image in the list.

So you shouldn't call this method if the image is already animating. You can call isAnimating method to check if image is animating.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM