Swift连续旋转动画不是那么连续 [英] Swift Continuous Rotation Animation not so continuous
问题描述
这是我的代码。意图是连续旋转名为swirls [l]的UIImageView。但是,每个旋转开始/结束之间会有一个小的暂停。我已经完成了每一个动画教程,但无法弄清楚错误是什么?
Here is my code. Intent is to continuously rotate the UIImageView named swirls[l]. However, there is a small pause between every rotation start/end. I have gone through every single animation tutorial but cant figure out what the mistake is?
let fullRotation = CGFloat(M_PI * 2)
let duration = 2.0
let delay = 0.0
let options = UIViewKeyframeAnimationOptions.Repeat | UIViewKeyframeAnimationOptions.CalculationModeLinear
UIView.animateKeyframesWithDuration(duration, delay: delay, options: options, animations: {
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/3, animations: {
swirls[l].transform = CGAffineTransformMakeRotation(1/3 * fullRotation)
})
UIView.addKeyframeWithRelativeStartTime(1/3, relativeDuration: 1/3, animations: {
swirls[l].transform = CGAffineTransformMakeRotation(2/3 * fullRotation)
})
UIView.addKeyframeWithRelativeStartTime(2/3, relativeDuration: 1/3, animations: {
swirls[l].transform = CGAffineTransformMakeRotation(3/3 * fullRotation)
})
}, completion: {finished in
})
编辑:我看到有人建议先前的解决方案可用,但它不能用于连续不间断的旋转。对我有用的唯一技巧是我在下面选择的答案。谢谢
I see that it has been suggested that a previous solution is available, but it simply does not work for continuous uninterrupted rotation. The only trick that worked for me is the answer that I chose below. Thanks
推荐答案
我不确定您的代码有什么问题,但我已经使用这种方法实现了连续轮换,
I'm not sure what's wrong with your code, but I've implemented continuous rotation using this method,
@IBAction func rotateView(sender: UIButton) {
UIView.animateWithDuration(0.5, delay: 0, options: .CurveLinear, animations: { () -> Void in
self.spinningView.transform = CGAffineTransformRotate(self.spinningView.transform, CGFloat(M_PI_2))
}) { (finished) -> Void in
self.rotateView(sender)
}
}
这篇关于Swift连续旋转动画不是那么连续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!