From bced3600fc3ddb710f3aa5029945fd11fb08367a Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 24 Jul 2020 12:19:48 -0400 Subject: [PATCH] adjust wheel animation to remain on CALayer and not hitting main CPU thread on every cycle. --- MVMCoreUI/Atomic/Atoms/Views/Wheel.swift | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift index da71ea0f..d81af71c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Wheel.swift @@ -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) - } - } -}