【问题标题】:iOS5 CGAffineTransformMakeRotation doesn't work the second time I do it?iOS5 CGAffineTransform Make Rotation 在我第二次做时不起作用?
【发布时间】:2012-04-14 18:30:51
【问题描述】:

我有简单的旋转变换,结合了 alpha,在第一次调用时效果很好,但是第二次旋转没有发生(用户通过点击屏幕来启动这个动画)。

这是我的基本动画功能:

- (void) animateMe:(UIImageView *)myImage delay:(NSTimeInterval)dly
{
    [UIView animateWithDuration:1.0 
                          delay:dly
                        options:UIViewAnimationOptionAutoreverse
                     animations:^(void){
                         myImage.alpha = 1.0;
                         myImage.transform = CGAffineTransformMakeRotation(180.0);
                     }
                     completion:^(BOOL finished) {
                         myImage.alpha = 0.0;
                  }];
}

【问题讨论】:

    标签: animation ios5 cgaffinetransform image-rotation


    【解决方案1】:

    问题是第二次要旋转视图时,已经旋转了180度和线:

    myImage.transform = CGAffineTransformMakeRotation(180.0);
    

    相当于:

    myImage.transform = myImage.transform;
    

    所以你应该这样做:

    myImage.transform = CGAffineTransformRotate(myImage.transform, 180.0);
    

    请注意,documentation 表示旋转角度应以弧度为单位,而不是度数。所以你可能应该使用M_PI 而不是180.0

    另外,请注意documentation 表示UIViewAnimationOptionAutoreverse 必须UIViewAnimationOptionRepeat 结合使用。

    UIViewAnimationOptionAutoreverse

    前后运行动画。必须与 UIViewAnimationOptionRepeat 选项结合使用。

    【讨论】:

    • 谢谢,这很有帮助!我会尝试您的建议并分配检查是否有效,听起来您可能是对的。很惊讶他们会使用弧度——这似乎是一种尴尬的方式,但我明白文档是这么说的。
    • 好吧,我花了一点时间才意识到 CGAffineTransformRotate() 是一个与 CGAffineTransformMakeRotation() 不同的函数!你的建议有效,谢谢。您的链接非常有帮助,我学到了很多关于仿射变换的知识。
    • 还有一条评论,我一直在阅读有关块动画的文档,它说您可以结合 UIViewAnimationOptionAutoReverse 指定重复计数——不需要与 UIViewAnimationAutoRepeat 结合。
    猜你喜欢
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2018-06-15
    • 2016-03-30
    • 2021-08-26
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多