Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cancel a UIView animateWithDuration before completion

I have this code in my project:

- (void) fadeImageView {
    [UIView animateWithDuration:1.0f
                          delay:0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         self.imageView.alpha = 0.0f;
                     }
                     completion:^(BOOL finished) {
                         //make the image view un-tappable.
                         //if the fade was canceled, set the alpha to 1.0
                     }];

}

however, there are circumstance where i would like to cancel this operation before the imageview has become invisible. Is there a way to cancel this animation mid animation?

like image 723
Sean Danzeiser Avatar asked Aug 24 '12 00:08

Sean Danzeiser


1 Answers

From Apple docs: Use of this method is discouraged in iOS 4.0 and later. Instead, you should use the animateWithDuration:delay:options:animations:completion: method to specify your animations and the animation options.:

[UIView animateWithDuration:1.f
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     self.imageView.alpha = 0.0f;
} completion:NULL];
like image 99
Borut Tomazin Avatar answered Sep 22 '22 18:09

Borut Tomazin