I will answer my own question to share my solution for this piece of code.
How can i rotate any view continuously with a constant speed in IOS Swift 3?
I will answer my own question to share my solution for this piece of code.
How can i rotate any view continuously with a constant speed in IOS Swift 3?
Here is a simple class to rotate a view continuously at a constant speed. In this example, 1 complete tour in 1 second.
class Rotator
{
private static var some_view : UIView = UIView()
private static var some_timer : Timer = Timer()
class func Rotate(some_view : UIView)
{
self.some_view = some_view
some_timer.invalidate()
some_timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(rotateView), userInfo: nil, repeats: true)
}
@objc private class func rotateView()
{
UIView.animate(withDuration: 1, delay: 0, options: .curveLinear, animations: { () -> Void in
some_view.transform = some_view.transform.rotated(by: CGFloat(Double.pi))
})
}
}
And the usage is:
myImage = UIImageView()
Rotator.Rotate(some_view: myImage)
Hope this helps.