如何使用 CFaffineTransform 创建多个 UIImageView 动画,在上一个动画结束后开始一个动画

发布于 2024-12-01 18:55:49 字数 789 浏览 2 评论 0原文

首先感谢您阅读我的问题。我当前正在尝试使用 CFaffineTransform 执行多个动画来复制 kens burn 效果。

尝试实现:缩放图像,然后将图像平移到右侧。

问题:一旦开始第二个动画,我的图像将相对于原始图像平移,而不是相对于第一个图像的最终产品平移。这不是我想要达到的效果。

第一个动画是放大图像。

[UIView beginAnimations:@"zoomin" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform zoomIn = CGAffineTransformMakeScale(5.8, 5.8);

imageView.transform = zoomIn;

[UIView commitAnimations];

第二个动画是将图像向左平移。

[UIView beginAnimations:@"panning" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

imageView.transform = moveRight;

[UIView commitAnimations];

第二个动画代码仅在第一个动画结束后调用。

firstly thank you for reading my question. I'm current trying to execute multiple animations using CFAffineTransform to replicate the kens burn effect.

Try to achieve: Zoom to to the image, then pan the image to the right.

Problem: Once I start the 2nd animation, my image will be panning relatively to the original image instead of panning relative to the end product of the 1st image. Which is not the effect I'm trying to achieve.

1st animation is to zoom into the image.

[UIView beginAnimations:@"zoomin" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform zoomIn = CGAffineTransformMakeScale(5.8, 5.8);

imageView.transform = zoomIn;

[UIView commitAnimations];

2nd animation is to pan the image to the left.

[UIView beginAnimations:@"panning" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

imageView.transform = moveRight;

[UIView commitAnimations];

2nd animation codes is only called after the first animation ends.

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

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

发布评论

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

评论(1

盛夏尉蓝 2024-12-08 18:55:49

它不起作用,因为您使用的是 CGAffineTransformMakeTranslation,这意味着它应该从原始位置开始(仿射是单位矩阵,并将视图置于未变换状态),您应该使用的是 CGAffineTransformTranslate,它采用所需的 (或当前变换)矩阵作为第一个参数。

因此,如果您这样做:

CGAffineTransform moveRight = CGAffineTransformTranslate(imageView.transform ,200, 0);

您使用的

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

内容与:

CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity ,200, 0);

我建议您阅读一篇很棒的文章 揭秘 CGAffineTransform

It does not work because you are using CGAffineTransformMakeTranslation, which means that it should start from the original position (affine is identity matrix, and puts the view in the un-transformed state), what you should use is CGAffineTransformTranslate, which takes the desired (or current transform) matrix as the first argument.

So if you do:

CGAffineTransform moveRight = CGAffineTransformTranslate(imageView.transform ,200, 0);

You used

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

which is the same as:

CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity ,200, 0);

I suggest you read a great post Demystifying CGAffineTransform

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