【发布时间】:2015-07-03 09:26:40
【问题描述】:
如何将 ImageView 从 0 旋转到 360 度?
这段代码让我把它旋转 180 度:
func rotateTimes(){
UIView.animateWithDuration(5, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, 180 * 0.0174532925)
}, completion: nil)
}
但我想旋转随机度数,而不仅仅是 180 度。
我试过了:
func rotateTimes(){
let diceRoll = Int(arc4random_uniform(7))
UIView.animateWithDuration(5, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, self.diceRoll * 0.0174532925)
}, completion: nil)
}
但这不起作用..
【问题讨论】:
-
你的
diceRoll的当前值是多少? -
@Christian It´s... random(?)
-
是的,我知道。但它是否足够大以至于它的价值足以旋转它?例如,如果该值介于 0 和 1 之间,则旋转不可见。
-
刚才的值在1到10之间进行测试..
-
尝试一些更高的值,比如 50 到 80 之间。1 到 10 是不可见的。我认为您的代码应该可以工作。