【问题标题】:Spin UIImageView 360 Degrees using UIView animations?使用 UIView 动画旋转 UIImageView 360 度?
【发布时间】:2012-12-04 06:20:28
【问题描述】:

我只是想用这个顺时针旋转 UIImageView 360 度:

#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)

还有这个

imageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(360));

然而 imageView 根本不旋转,即使是它被调用的那些。我做错了什么吗?我不想使用 CAAnimations,所以请不要推荐我这样做。

谢谢!

【问题讨论】:

    标签: ios animation rotation transform


    【解决方案1】:

    问题在于 Core Animation 会通过寻找从当前状态到新状态的最直接路径来应用动画。旋转 0 度与旋转 360 度相同,因此最直接的最终变换方法是完全不做任何事情。

    两个 180 度的步长会有问题,因为从 0 度到 180 度有两条同样直接的路线,Core Animation 可以选择其中任何一个。所以你可能需要把你的动画分成三个步骤。第一个使用UIViewAnimationOptionCurveEaseIn,第二个使用UIViewAnimationOptionCurveLinear,最后一个使用UIViewAnimationOptionCurveEaseOut。

    【讨论】:

      【解决方案2】:

      也许是因为转换不会在一段时间内发生。在我看来,只要随着时间的推移无法察觉,您可能需要在一小段时间内执行转换或转换序列。

      【讨论】:

        【解决方案3】:

        这是受 Tommy 回答启发的代码。

        我用过

        NSInteger step;
        

        跟踪图像视图的当前旋转度数。

        - (void)startAnimation
        {
            [UIView animateWithDuration:0.5f 
                                  delay:0.0f 
                                options:UIViewAnimationOptionCurveLinear 
                             animations:^{
                imageView.transform = CGAffineTransformMakeRotation(120 * step / 180.0f * M_PI);
            }
                             completion:^(BOOL finished) {
                step++;
                // rotation completed, reset for the next round
                if (step == 4){
                    step = 1;
                }
        
                // perform the next rotation animation
                [self startAnimation];
            }];
        }
        

        【讨论】:

          猜你喜欢
          • 2011-03-26
          • 2012-04-08
          • 1970-01-01
          • 1970-01-01
          • 2015-10-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多