2011-08-31 30 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