使用 CAKeyframeAnimation 在动画期间操作 UIImageView

发布于 2024-12-02 07:58:38 字数 804 浏览 2 评论 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];

I need to move object (UIImageView) from point A to point B, then rotate image at point B by 180 degrees to face the opposite direction and move object from B to A (backwards).

I have the code below which moves from A to B. I also know how to rotate UIImageView. But how to know when object has reached point B and how to apply rotation action considering there are many objects on the screen?

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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2024-12-09 07:58:38

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

OTOH,您描述的动画听起来好像可以通过 UIView 的动画支持轻松完成。请参阅 使用块对视图进行动画处理,或者动画视图(如果您仍以早期版本为目标)。

Set a delegate on the CAAnimation object, and in the delegate implement the animationDidStop:finished: method.

OTOH, the animation you described sounds like it could be done easily enough with UIView's animation support. See Animating Views with Blocks if you're targeting 4.0 and up, or Animating Views if you're still targeting earlier versions.

我的黑色迷你裙 2024-12-09 07:58:38

您可以使用 CAAnimation 委托方法

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

You can use the CAAnimation delegate method

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文