2009-04-03 9 views

Trả lời

4

Đây có thể không phải là giải pháp tốt nhất, nhưng nó có hiệu quả đối với tôi. Tôi đã nói với các hình ảnh động để autoreverse, sau đó bắt đầu nó nửa chừng. Nhưng để ngăn chặn nó từ hoạt hình trở lại một lần nữa tôi cần phải chấm dứt nó sớm.

- (void) animate { 
    CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
    pathAnimation.path = path; 
    pathAnimation.duration = 15.0; 
    pathAnimation.calculationMode = kCAAnimationPaced; 
    pathAnimation.timeOffset = pathAnimation.duration; 
    pathAnimation.autoreverses = YES; 

    NSString * key = @"pathAnimation"; 
    [animatedView.layer addAnimation:pathAnimation forKey:key]; 
    [NSTimer scheduledTimerWithTimeInterval:pathAnimation.duration target:self selector:@selector(endAnimation:) userInfo:key repeats:NO]; 
} 

- (void) endAnimation:(NSTimer *)timer { 
    [animatedView.layer removeAnimationForKey:timer.userInfo]; 
} 

Nếu có cách nào tốt hơn, tôi muốn biết.

28
animation.speed = -1; 

?

+0

Đúng. Điều đó chắc chắn tốt hơn. Tôi ước gì tôi nghĩ về điều đó sớm hơn. –

+0

Cảm ơn rất nhiều! – BoilingLime

+0

Bạn đã học ở đâu? Tôi không thể tìm thấy trong tài liệu táo tính năng này. – surfrider