我在我的项目的代码:
- (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
}];
}
但是,也有情况在这里我想取消此操作前的ImageView已变得不可见。 有没有办法取消这个动画中旬动画?
更新:喜欢这个答案https://stackoverflow.com/a/21527129/194309从博鲁特Tomazin
从苹果的文档: 此方法的使用中的iOS 4.0及更高版本气馁。 相反,你应该使用 animateWithDuration:delay:options:animations:completion:
方法来指定动画和动画选项:
[UIView animateWithDuration:1.f
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.imageView.alpha = 0.0f;
} completion:NULL];
首先你必须UIViewAnimationOptionAllowUserInteraction添加到像选项..
- (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
}];
}
然后做出这样的方法....
-(void)stopAnimation {
[self.routeView.layer removeAllAnimations];
}
之后,当你想使用删除上述方法动画随叫随到.....
[self performSelectorOnMainThread:@selector(stopAnimation) withObject:nil waitUntilDone:YES];
希望它会帮助你
快乐编码......... !!!!!!!!!!!! :)
编辑:
由于user1244109来指导我的。
对于iOS7我们必须增加一个选项UIViewAnimationOptionBeginFromCurrentState
喜欢:
[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
}];