J.K Jeon
J.K Jeon

Reputation: 270

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?

Upvotes: 1

Views: 770

Answers (2)

Stuart
Stuart

Reputation: 37053

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];
                 }];

Upvotes: 1

SentineL
SentineL

Reputation: 4732

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.

Upvotes: 0

Related Questions