【问题标题】:How would I lower the speed of the rotation to 0 in Swift?如何在 Swift 中将旋转速度降低到 0?
【发布时间】:2016-07-24 22:14:27
【问题描述】:

我有这段代码可以旋转我的图像视图,但是当我按下暂停按钮时,我希望旋转速度为 0。我该怎么做?

@IBAction func playButtonL(sender: AnyObject) {

    rotation.toValue = NSNumber(double: M_PI * 2)
    rotation.duration = 2
    rotation.cumulative = true
    rotation.repeatCount = FLT_MAX
    self.leftCircleImageView.layer.addAnimation(rotation, forKey: "rotationAnimation")
}


@IBAction func pauseButtonR(sender: AnyObject) {


}

【问题讨论】:

  • 它可以工作,但我有一个问题是它停止时会回到原来的位置。我想要它让它停在它所在的位置。
  • 如果它适合您,请接受答案。

标签: ios xcode swift uiviewanimation


【解决方案1】:

为了减少你可以使用的动画时间

rotation.duration = 2

要停止重置它的状态默认值,您可以使用

cabasicanimation.removedOnCompletion = NO;

cabasicanimation.fillMode = kCAFillModeForwards;

回答学分和参考:

CABasicAnimation resets to initial value after animation completes

希望对您有所帮助!如果您需要任何进一步的帮助,请告诉我。

【讨论】:

  • 我把代码放在了错误的按钮上。我尝试了所有 3 行代码,圆圈一直在旋转。
  • 它根本没有停止。我做了 rotation.fillMode = kCAFillModeForwards 和另外两行代码,它并没有停在它的最终位置。
  • 圆圈由于某种原因仍在旋转。如果我添加行 self.leftCircleImageView.layer.removeActionWithKey(rotation, "rotationAnimation") 它会停止但会重置到原始位置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-06
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 2011-05-27
  • 1970-01-01
相关资源
最近更新 更多