adjust wheel animation to remain on CALayer and not hitting main CPU thread on every cycle.
This commit is contained in:
parent
f9ce6e9f0f
commit
bced3600fc
@ -11,7 +11,7 @@ import UIKit
|
||||
@objcMembers open class Wheel: View, MVMCoreUIViewConstrainingProtocol {
|
||||
|
||||
var heightConstraint: NSLayoutConstraint?
|
||||
var gradientLayer: CALayer?
|
||||
weak var gradientLayer: CALayer?
|
||||
var graphModel: WheelModel? {
|
||||
return model as? WheelModel
|
||||
}
|
||||
@ -170,20 +170,9 @@ import UIKit
|
||||
rotation.timingFunction = CAMediaTimingFunction(name: .linear)
|
||||
rotation.fillMode = .both
|
||||
rotation.isRemovedOnCompletion = false
|
||||
rotation.repeatCount = Float.greatestFiniteMagnitude
|
||||
|
||||
//avoid infinity animation take high CPU momery usage when layer is not displayed
|
||||
rotation.delegate = self
|
||||
rotation.repeatCount = 1
|
||||
self.gradientLayer?.add(rotation, forKey: "rotation")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Wheel: CAAnimationDelegate {
|
||||
public func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
|
||||
if let object = graphModel {
|
||||
rotationAnimation(object)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user