J'ai ce code dans mon projet:
- (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 }]; }
Cependant, il y a des circonstances où je voudrais annuler cette opération avant que l'image soit devenue invisible. Y a-t-il un moyen d'annuler cette animation au milieu de l'animation?
cela pourrait aider
[UIView animateWithDuration:0.001 animations:^{ [UIView setAnimationBeginsFromCurrentState:YES]; self.imageView.alpha = 1; }];
Tout d'abord, vous devez append UIViewAnimationOptionAllowUserInteraction à l'option like ..
- (void) fadeImageView { [UIView animateWithDuration:1.0f delay:0 options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction 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 }]; }
puis faites une méthode comme celle-ci ….
-(void)stopAnimation { [self.routeView.layer removeAllAnimations]; }
après cela, lorsque vous voulez supprimer votre appel d'animation ci-dessus la méthode en utilisant …..
[self performSelectorOnMainThread:@selector(stopAnimation) withObject:nil waitUntilDone:YES];
J'espère que cela vous aidera
Bonne codification ……… !!!!!!!!!!!! 🙂
MODIFIER:
Merci user1244109 pour me guider pour ça.
Pour iOS7, nous devons append une autre option UIViewAnimationOptionBeginFromCurrentState
comme:
[UIView animateWithDuration:1.0f delay:0 options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState 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 }];
D'Apple docs: L' utilisation de cette méthode est déconseillée dans iOS 4.0 et versions ultérieures. Au lieu de cela, vous devez utiliser la animateWithDuration:delay:options:animations:completion:
pour spécifier vos animations et les options d'animation .:
[UIView animateWithDuration:1.f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.imageView.alpha = 0.0f; } completion:NULL];