2013-10-31 30 views
0

我打电话给viewDidLoad函数[self moveFishLeft]和对象正确动画,但当我试图删除touchesBeganWithEvent动画仍然存在。那么如何在屏幕触摸上删除所有左右功能动画。如何删除触摸uiviewanimation块

- (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]; 
} 

回答

0

请参考下面的代码: - [self.view.layer removeAllAnimations];使用,这可能是它是有用的。

+0

。它仍然不起作用。 –

+0

当我点击屏幕时,动画会从frame.origin.x = 0或frame.origin.x = 530中重新开始。 –

+0

当你想停止动画时添加这行代码[UIView commitAnimations]; –

0

你忘了所有包装的 “removeAllAnimations” 在CATransaction:

(需要QuartzCore进口)我已经用它

[CATransaction begin]; 
[optionView1.layer removeAllAnimations]; 
[optionView2.layer removeAllAnimations]; 
[optionView3.layer removeAllAnimations]; 
[optionView4.layer removeAllAnimations]; 
[optionView5.layer removeAllAnimations]; 
[optionView6.layer removeAllAnimations]; 
[CATransaction commit]; 
+0

我猜它仍然不能正常工作。当我点击屏幕时,动画会从frame.origin.x = 0或frame.origin.x = 530中重新开始。 –