@@ -51,8 +51,6 @@ open class SpringIndicator: UIView {
5151 return rotateDuration / 2
5252 }
5353
54- fileprivate var stopAnimationsHandler : ( ( SpringIndicator ) -> Void ) ?
55-
5654 public override init ( frame: CGRect ) {
5755 indicatorView = UIView ( frame: CGRect ( x: 0 , y: 0 , width: frame. width, height: frame. height) )
5856 super. init ( frame: frame)
@@ -240,8 +238,6 @@ open class SpringIndicator: UIView {
240238public extension SpringIndicator {
241239 /// If start from a state in spread is True.
242240 public func startAnimation( _ expand: Bool = false ) {
243- stopAnimationsHandler = nil
244-
245241 if isSpinning ( ) {
246242 return
247243 }
@@ -255,11 +251,15 @@ public extension SpringIndicator {
255251 /// true is wait for stroke animation.
256252 public func stopAnimation( _ waitAnimation: Bool , completion: ( ( SpringIndicator ) -> Void ) ? = nil ) {
257253 if waitAnimation {
258- stopAnimationsHandler = { indicator in
259- indicator. stopAnimation ( false , completion: completion)
254+ if let layer = pathLayer? . presentation ( ) {
255+ let time = Double ( 2 - layer. strokeStart - layer. strokeEnd)
256+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + time) {
257+ self . stopAnimation ( false , completion: completion)
258+ }
259+ } else {
260+ stopAnimation ( false , completion: completion)
260261 }
261262 } else {
262- stopAnimationsHandler = nil
263263 indicatorView. layer. removeAllAnimations ( )
264264 pathLayer? . strokeEnd = 0
265265 pathLayer = nil
0 commit comments