我想永远旋转一个imageview。我尝试了以下代码:
UIView.animateWithDuration(3, animations: {
self.loginLogo.transform = CGAffineTransformMakeRotation((360 * CGFloat(M_PI)) / 360)
}){ (finished) -> Void in
self.rotateImage()
}
但这有一段时间了。我的imageview并没有永远旋转。我该如何解决?
答案 0 :(得分:1)
如果您想永久旋转图像,可以这样做:
func rotateViewLayer() {
let rotateView = CABasicAnimation()
rotateView.fromValue = 0.degreesToRadian
rotateView.toValue = 360.degreesToRadian
rotateView.duration = 1
rotateView.repeatCount = Float.infinity
rotateView.removedOnCompletion = false
rotateView.fillMode = kCAFillModeForwards
rotateView.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
imageView.layer.addAnimation(rotateView, forKey: "transform.rotation.z")
}
这是你的助手扩展:
extension Int {
var degreesToRadian : CGFloat {
return CGFloat(self) * CGFloat(M_PI) / 180.0
}
}
您可以参考THIS示例项目获取更多信息。
答案 1 :(得分:0)
在视图层使用此功能
var $j = $.noConflict();
答案 2 :(得分:0)
这应该有效
func startAnimationWithDuration(duration:CGFloat)
{
var rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.fromValue = 0
rotationAnimation.toValue = 2 * M_PI
rotationAnimation.duration = NSTimeInterval(duration)
rotationAnimation.repeatCount = 1000.0 //some large value
imageView.layer.addAnimation(rotationAnimation, forKey: "spin")
}