gpt4 book ai didi

ios - 旋转 ImageView 动画

转载 作者:行者123 更新时间:2023-11-28 07:04:49 24 4
gpt4 key购买 nike

我想永远旋转 ImageView 。我尝试了以下代码:

    UIView.animateWithDuration(3, animations: {
self.loginLogo.transform = CGAffineTransformMakeRotation((360 * CGFloat(M_PI)) / 360)
}){ (finished) -> Void in
self.rotateImage()
}

但这是一次性的。我的 ImageView 不会永远旋转。我该如何解决?

最佳答案

如果你想永远旋转你的图像,你可以这样做:

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示例项目以获取更多信息。

关于ios - 旋转 ImageView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30955045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com