我需要將對象(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];
我其實有一條複雜的路徑可以穿行。爲了簡單起見,我使用A和B. YOu提到CGAnimation,但我沒有初始化該對象。我會研究如何去做。謝謝 – Vad
@Vad:我的意思是CAAnimation,它是CAKeyframeAnimation的超類。蘋果爲他們的課程設置了許多不同的小前綴。 – Anomie