xcode - Rotate imageview a random degree -


how can rotate imageview random degree 0 360?

this code let´s me rotate 180 degrees:

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)     } 

but want rotate random degree, not 180 degrees.

i have tried:

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)     } 

but doesn´t work..

try this:

let random = arc4random_uniform(1000) let angle = double(2*pi*1000)/ double(random) uiview.animatewithduration(5,    delay: 0.0,    options: uiviewanimationoptions.curvelinear,         animations:    { () -> void in     self.imageview.transform =        cgaffinetransformrotate(angle)   },    completion: nil) 

(you'll need define pi. if remember correctly have import darwin, , m_pi constant available.)


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -