0

関数 [self moveFishLeft] を viewDidLoad から呼び出しており、オブジェクトは適切にアニメーション化されていますが、touchesBeganWithEvent でアニメーションを削除しようとすると、アニメーションが残ります。では、画面タッチで左右の機能アニメーションをすべて削除するにはどうすればよいですか。

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

2 に答える 2

0

以下のコードを参照してください:- [self.view.layer removeAllAnimations]; これを使用すると便利です。

于 2013-10-31T08:44:26.840 に答える
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];
于 2013-10-31T09:04:20.077 に答える