gpt4 book ai didi

ios - 旋转图像查看随机

转载 作者:行者123 更新时间:2023-11-28 13:12:03 25 4
gpt4 key购买 nike

我试图让 ImageView 在 360 度到 720 度之间随机旋转。所以我希望 ImageView 旋转一次(360 度),然后再次旋转一个随机度数(0 到 360 度)

func rotateRandom2(){
let lower : UInt32 = 360
let upper : UInt32 = 720
let diceRoll = CGFloat(arc4random_uniform(upper - lower) + lower)
let degree = 0.0174532925 as CGFloat
let rotate = diceRoll
UIView.animateWithDuration(1, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
self.bottleImageView.transform = CGAffineTransformRotate(self.bottleImageView.transform, rotate)
}, completion: nil)
}

最佳答案

您可以使用 CABasicAnimation 为 z 轴旋转设置动画。你可以这样做:

let rotateView = CABasicAnimation()
let randonAngle = arc4random_uniform(361) + 360
rotateView.fromValue = 0
rotateView.toValue = Float(randonAngle) * Float(M_PI) / 180.0
rotateView.duration = 1
rotateView.repeatCount = 0
rotateView.removedOnCompletion = false
rotateView.fillMode = kCAFillModeForwards
rotateView.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
view.layer.addAnimation(rotateView, forKey: "transform.rotation.z")

关于ios - 旋转图像查看随机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30959031/

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