如何在IOS Swift 3中连续旋转视图
我将回答我自己的问题,分享我对这段代码的解决方案如何在IOS Swift 3中连续旋转视图,ios,animation,swift3,Ios,Animation,Swift3,我将回答我自己的问题,分享我对这段代码的解决方案 如何在IOS Swift 3中以恒定速度连续旋转任何视图?下面是一个简单的类,用于以恒定速度连续旋转视图。在本例中,1在1秒内完成巡更 class Rotator { private static var some_view : UIView = UIView() private static var some_timer : Timer = Timer() class func Rotate(some_view : U
如何在IOS Swift 3中以恒定速度连续旋转任何视图?下面是一个简单的类,用于以恒定速度连续旋转视图。在本例中,1在1秒内完成巡更
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))
})
}
}
用法是:
myImage = UIImageView()
Rotator.Rotate(some_view: myImage)
希望这有帮助。使用类静态是愚蠢的,这个问题以前已经被问过很多次了,所以不需要新的问题;如果你认为你有一个更好的答案,回答一个现有的问题。