Ios 如何在触摸时删除uiviewanimation块
我正在从viewDidLoad调用函数[self moveFishLeft],对象正在正确设置动画,但当我尝试删除TouchBeganWithEvent上的动画时,动画仍然保留。那么,如何删除触摸屏上的所有左右功能动画呢Ios 如何在触摸时删除uiviewanimation块,ios,objective-c,uiviewanimation,Ios,Objective C,Uiviewanimation,我正在从viewDidLoad调用函数[self moveFishLeft],对象正在正确设置动画,但当我尝试删除TouchBeganWithEvent上的动画时,动画仍然保留。那么,如何删除触摸屏上的所有左右功能动画呢 - (void)moveFishLeft { [UIView animateWithDuration:6.0f delay:0.0f options:UIV
- (void)moveFishLeft {
[UIView animateWithDuration:6.0f
delay:0.0f
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent
animations:^{
[optionView1 setFrame:CGRectMake(0, 480, 130, 110)];
[optionView2 setFrame:CGRectMake(0, 600, 130, 110)];
[optionView3 setFrame:CGRectMake(130, 530, 130, 110)];
[optionView4 setFrame:CGRectMake(130, 670, 130, 110)];
[optionView5 setFrame:CGRectMake(130, 780, 130, 110)];
[optionView6 setFrame:CGRectMake(0, 720, 130, 110)];
}
completion:^(BOOL finished) {
[optionView1.layer removeAllAnimations];
[optionView2.layer removeAllAnimations];
[optionView3.layer removeAllAnimations];
[optionView4.layer removeAllAnimations];
[optionView5.layer removeAllAnimations];
[optionView6.layer removeAllAnimations];
[optionImage1 setImage:[UIImage imageNamed:@"fish1_right"]];
[optionImage2 setImage:[UIImage imageNamed:@"fish1_right"]];
[optionImage3 setImage:[UIImage imageNamed:@"fish1_right"]];
[optionImage4 setImage:[UIImage imageNamed:@"fish1_right"]];
[optionImage5 setImage:[UIImage imageNamed:@"fish1_right"]];
[optionImage6 setImage:[UIImage imageNamed:@"fish1_right"]];
[self moveFishRight];
}];
}
- (void)moveFishRight {
[UIView animateWithDuration:6.0f
delay:0.0f
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent
animations:^{
[optionView1 setFrame:CGRectMake(530, 480, 130, 110)];
[optionView2 setFrame:CGRectMake(530, 600, 130, 110)];
[optionView3 setFrame:CGRectMake(638, 530, 130, 110)];
[optionView4 setFrame:CGRectMake(638, 670, 130, 110)];
[optionView5 setFrame:CGRectMake(638, 780, 130, 110)];
[optionView6 setFrame:CGRectMake(530, 720, 130, 110)];
}
completion:^(BOOL finished) {
[optionView1.layer removeAllAnimations];
[optionView2.layer removeAllAnimations];
[optionView3.layer removeAllAnimations];
[optionView4.layer removeAllAnimations];
[optionView5.layer removeAllAnimations];
[optionView6.layer removeAllAnimations];
[optionImage1 setImage:[UIImage imageNamed:@"fish1"]];
[optionImage2 setImage:[UIImage imageNamed:@"fish1"]];
[optionImage3 setImage:[UIImage imageNamed:@"fish1"]];
[optionImage4 setImage:[UIImage imageNamed:@"fish1"]];
[optionImage5 setImage:[UIImage imageNamed:@"fish1"]];
[optionImage6 setImage:[UIImage imageNamed:@"fish1"]];
[self moveFishLeft];
}];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[optionView1.layer removeAllAnimations];
[optionView2.layer removeAllAnimations];
[optionView3.layer removeAllAnimations];
[optionView4.layer removeAllAnimations];
[optionView5.layer removeAllAnimations];
[optionView6.layer removeAllAnimations];
}
请参阅以下代码:-
[self.view.layer removeAllAnimations]代码>使用此选项可能很有用。您忘记将所有“RemoveAllanimation”包装在CATTransaction中:
(需要QuartzCore导入)
我想它还是不起作用。当我在屏幕上单击时,动画从frame.origin.x=0或frame.origin.x=530重新启动。当我在屏幕上单击时,动画从frame.origin.x=0或frame.origin.x=530重新启动。当您想要停止动画[UIView commitAnimations]时,请添加此行代码;
[CATransaction begin];
[optionView1.layer removeAllAnimations];
[optionView2.layer removeAllAnimations];
[optionView3.layer removeAllAnimations];
[optionView4.layer removeAllAnimations];
[optionView5.layer removeAllAnimations];
[optionView6.layer removeAllAnimations];
[CATransaction commit];