cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: animation that don't call completion quickly

I have this code to simulate a multiple camera flash

[UIView animateWithDuration:0.1
                      delay:0.f
                    options:UIViewAnimationOptionAutoreverse
                 animations:^{
                                [UIView setAnimationRepeatCount:2];
                                flash.alpha=1.f;
                             }
                 completion:^(BOOL finished) {
                                flash.alpha = 0;
                             }];

flash is a white UIImageView (full screen) that starts with alpha = 0.
If you try to use this code, you will notice that at the end flash remains full white for a little time and it's not perfect for my effects, what can I do to solve this?

Upvotes: 0

Views: 157

Answers (1)

TotoroTotoro
TotoroTotoro

Reputation: 17622

The problem with your code is you do autoreverse using the option UIViewAnimationOptionAutoreverse, while also specifying your own final state in the completion block.

Try this:

[UIView animateWithDuration:0.1f
                      delay:0
                    options:UIViewAnimationOptionAutoreverse
                 animations:^{
                                [UIView setAnimationRepeatCount:2];
                                flash.alpha=1.f;
                             }
                 completion:nil];

Upvotes: 1

Related Questions