【问题标题】:Creating a constant spinning UIImageView创建一个不断旋转的 UIImageView
【发布时间】:2012-08-13 16:08:58
【问题描述】:

我尝试过使用这样的核心动画:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{ CGAffineTransform transform = CGAffineTransformMakeRotation(3.14);
        self->inner.transform = transform;
    } completion:NULL];
}

这会旋转我的称为外部的 UIImageView,但是在平滑之后它并没有完成 360 度旋转。它在它的 3/4 左右之后跳跃。我不应该在 PI 上轮换吗?

如果我想改变旋转的方向,我该怎么做?它每分钟顺时针旋转。

谢谢

【问题讨论】:

  • 这不是很好的做法...您应该使用自己的动画,而不是让UIView 不断为您旋转。
  • 我应该使用石英或类似的东西吗?
  • 你可以。或者,如果您没有动态内容,只需创建一个图像数组并使用 UIImageView 对象的 animationImages
  • 尝试使用 M_PI 而不是 3.14 并将值设置为负以反转方向
  • 谢谢,我试过了,但还是不行

标签: objective-c rotation core-animation pi


【解决方案1】:

如果其他人在任何时候需要这个:

//outer ring
CABasicAnimation *fullRotationAnimation;
fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
fullRotationAnimation.toValue = [NSNumber numberWithFloat:2 * M_PI];
fullRotationAnimation.duration = 4;
fullRotationAnimation.repeatCount = 5000;
//fullRotationAnimation.cumulative = YES;
[self->outer.layer addAnimation:fullRotationAnimation forKey:@"360"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多