iosuiviewuianimationquartz-core

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?


Solution

  • Update: prefer this answer https://stackoverflow.com/a/21527129/194309 from Borut Tomazin