动画旋转

发布于 2024-07-29 23:08:21 字数 622 浏览 1 评论 0原文

可能的重复:
为什么 CAAnimation 旋转会返回到之前的状态

我正在尝试使用 CATransform3DMakeRotation 对旋转进行动画处理,但问题是一旦动画完成,图像就会返回到其初始位置,即返回到零。 但我想将其保留在完成旋转的位置。 我该怎么做呢?

编辑 我想做的是创建与新 iPhone 相同的指南针。 基本上,位置管理器每隔几秒(或每秒几个)就会给我新的标题。 使用新的标题和时间戳,我试图获得平滑的图像动画,但没有取得任何进展。 似乎唯一有效的方法是直接应用变换,例如,

compassimage.layer.transform = CATransform3DMakeRotation(newHeading.trueHeading *M_PI/180,0,0,1.0): 

但这不是动画的......

Possible Duplicate:
Why CAAnimation Rotation is returning to previous state

I'm trying to animate a rotation using CATransform3DMakeRotation, but the problem is once the animation is finished, the image goes back to its initial position, i.e back to zero. But I'd like to keep it where it finished rotating. How would I do that?

edit
What I'm trying to do is to create the same compass which comes with the new iPhone. Basically the locationmanager gives me new headings every few seconds (or several per second). Using the new heading and the timestamp, I was trying to get a smooth animation of the image but not getting anywhere. The only thing which seems to work is applying the transform directly, e.g.

compassimage.layer.transform = CATransform3DMakeRotation(newHeading.trueHeading *M_PI/180,0,0,1.0): 

but that's not animated...

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

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

发布评论

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

评论(3

勿忘初心 2024-08-05 23:08:23

好吧,回到基础知识,只是尝试将图像旋转 90 度并保持原样。 将以下代码添加到 - (void)viewDidLoad,但即使它旋转,一旦动画完成,它仍然会返回到其初始位置

CATransform3DrotationTransform = CATransform3DMakeRotation(M_PI, 0, 0, 1.0);

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
rotationAnimation.duration = 2.0f;
rotationAnimation.removedOnCompletion = NO;

[image.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

Ok, back to basics, just trying to rotate an image by 90 degrees and keeping it there. Added the following code to - (void)viewDidLoad but even though it rotates it still going back to it's initial position once the animation is finished

CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 0, 0, 1.0);

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
rotationAnimation.duration = 2.0f;
rotationAnimation.removedOnCompletion = NO;

[image.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
可爱暴击 2024-08-05 23:08:23

您所要做的就是更改该数字,使其为负值。

compassimage.layer.transform = CATransform3DMakeRotation(-newHeading.trueHeading *M_PI/180,0,0,1.0):

all you have to do is change the figure so that it is negative.

compassimage.layer.transform = CATransform3DMakeRotation(-newHeading.trueHeading *M_PI/180,0,0,1.0):
稳稳的幸福 2024-08-05 23:08:22

您应该设置 animation.removedOncompletion 为 NO

You should set the animation.removedOncompletion to NO

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