简体   繁体   中英

How can I control UIView animation repeat cycle?

I'm afraid that the title is correct english expression but,

I have an animation on iOS with 4 scenes.

I used setAnimationDidStopSelector: method.

Here's the question: How can I make stopping function for the animation?

In iOS 4 and later you should use block based animation. Using these newer methods you can very easily specify some code to run once the animation has finished. For example:

[UIView animateWithDuration:1.0
                 animations:^{
                     // This code will be animated for 1 second.
                     [anObject setAlpha:0.0];
                 }
                 completion:^(BOOL finished) {
                     // This code will be executed once the animation has completed.
                     [anObject removeFromSuperview];
                 }];

A little ugly, but pretty lazy: add a flag to know when it should animate, and when not. Put your animation under if block (or something same) and just switch flag when you need.

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