2013-05-02 35 views
11

Tôi có 3 chế độ xem được tạo động bằng cách sử dụng vòng lặp. trong đó tôi gọi là phương pháp dưới đây để hình ảnh động xoayCách dừng UIView CABasicAnimation trong iPhone

- (void)runRightSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations: (CGFloat)rotations repeat:(float)repeat; 
{ 
    CABasicAnimation* rotationAnimation; 
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0]; 
    rotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 
    //rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; 
    rotationAnimation.duration = duration; 
    //rotationAnimation.cumulative = YES; 
    rotationAnimation.repeatCount = repeat; 

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; 
} 

làm thế nào tôi có thể ngăn chặn các hình ảnh động xoay liên lạc bắt đầu nhìn? ... tôi đã cố gắng mã hóa dưới đây liên lạc bắt đầu phương pháp nhưng nó đã không làm việc

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    int viewTag=[touch view].tag; 
    UIView *myView =(UIView *)[self.view viewWithTag:viewTag]; 
    [myView.layer removeAllAnimations]; 
} 

hãy giúp tôi ...

+1

thể trùng lặp của (http://stackoverflow.com/questions/2306870/is-there -a-way-to-pause-a-cabasicanimation) – Pfitz

Trả lời

23

Nó có thể là do bạn đang loại bỏ hình ảnh động từ các lớp khác chứ không phải là để loại bỏ hình ảnh động từ cùng một lớp bạn thêm hình ảnh động trên. (Bạn đang sử dụng chế độ xem sai để xóa hoạt ảnh, vui lòng kiểm tra lại).

Bạn có thể sử dụng để loại bỏ hình ảnh động từ yourView: [? Có cách nào để tạm dừng một CABasicAnimation]

[yourView.layer removeAllAnimations]; 
Các vấn đề liên quan