【问题标题】:How to create multiple UIImageView animations, starting one animation after previous animation ends using CFAffineTransform如何创建多个 UIImageView 动画,在上一个动画结束后使用 CFaffineTransform 开始一个动画
【发布时间】:2011-08-28 07:23:10
【问题描述】:

首先感谢您阅读我的问题。我目前正在尝试使用 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];

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

【问题讨论】:

    标签: iphone ios animation uiimageview cgaffinetransform


    【解决方案1】:

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

    如果你这样做:

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

    你用过

    CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);
    

    等同于:

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

    我建议你阅读一篇很棒的帖子Demystifying CGAffineTransform

    【讨论】:

    • 您好,非常感谢。它解决了我的问题,我找到了那篇文章,应该花一些时间阅读它!
    猜你喜欢
    • 2015-06-01
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多