2011-08-31 53 views
0

我需要將對象(UIImageView)從A點移動到B點,然後將B點處的圖像旋轉180度以面對相反的方向並將對象從B移動到A(向後)。使用CAKeyframeAnimation處理動畫期間處理UIImageView

我有下面的代碼從A移動到B.我也知道如何旋轉UIImageView。但是,考慮到屏幕上有很多物體,如何知道物體何時到達B點以及如何應用旋轉動作?

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
pathAnimation.duration = speed; 
pathAnimation.calculationMode = kCAAnimationPaced; 
pathAnimation.fillMode = kCAFillModeForwards; 
pathAnimation.removedOnCompletion = NO; 
CGMutablePathRef pointPath = CGPathCreateMutable(); 
CGPathMoveToPoint(pointPath, NULL, rect.origin.x, rect.origin.y); 
CGPathAddLineToPoint(pointPath, NULL, x, y); 
pathAnimation.path = pointPath; 
CGPathRelease(pointPath); 
[imageView.layer addAnimation:pathAnimation forKey:[NSString stringWithFormat:@"pathAnimation%@",objId]]; 
[imageView release]; 

回答

1

設置一個委託CAAnimation對象上,並在委託執行animationDidStop:finished:方法。

OTOH,您所描述的動畫聽起來好像可以用UIView的動畫支持輕鬆完成。如果您的目標是4.0或更高版本,請參閱Animating Views with Blocks;如果您仍然定位早期版本,請參閱Animating Views

+0

我其實有一條複雜的路徑可以穿行。爲了簡單起見,我使用A和B. YOu提到CGAnimation,但我沒有初始化該對象。我會研究如何去做。謝謝 – Vad

+0

@Vad:我的意思是CAAnimation,它是CAKeyframeAnimation的超類。蘋果爲他們的課程設置了許多不同的小前綴。 – Anomie

1

可以使用CAAnimation委託方法

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag 
+0

我正在研究如何做到這一點。謝謝 – Vad