0

我需要将对象(UIImageView)从 A 点移动到 B 点,然后将 B 点处的图像旋转 180 度以面向相反方向并将对象从 B 移动到 A(向后)。

我有下面的代码,它从 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];
4

2 回答 2

1

您可以使用 CAAnimation 委托方法

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
于 2011-08-31T14:58:27.170 回答
1

在 CAAnimation 对象上设置一个委托,并在委托中实现该animationDidStop:finished:方法。

OTOH,您描述的动画听起来可以通过 UIView 的动画支持轻松完成。如果您的目标是 4.0 及更高版本,请参阅使用 Blocks 动画视图或者如果您仍然针对早期版本,请参阅动画视图。

于 2011-08-31T15:02:32.113 回答