如何使用 CFaffineTransform 创建多个 UIImageView 动画,在上一个动画结束后开始一个动画
首先感谢您阅读我的问题。我当前正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为您使用的是 CGAffineTransformMakeTranslation,这意味着它应该从原始位置开始(仿射是单位矩阵,并将视图置于未变换状态),您应该使用的是 CGAffineTransformTranslate,它采用所需的 (或当前变换)矩阵作为第一个参数。
因此,如果您这样做:
您使用的
内容与:
我建议您阅读一篇很棒的文章 揭秘 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:
You used
which is the same as:
I suggest you read a great post Demystifying CGAffineTransform