我试图让图像视图在360和720之间旋转随机度。所以我希望图像视图旋转一次(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)
}
答案 0 :(得分:2)
您可以使用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")