From 692b2215c2daec7e7f99fa5967fdd3364e4af560 Mon Sep 17 00:00:00 2001 From: shu223 Date: Fri, 27 May 2016 14:35:08 +0100 Subject: [PATCH] Background support when it was stopped --- Pulsator/Pulsator.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Pulsator/Pulsator.swift b/Pulsator/Pulsator.swift index c01849e..2d048cf 100644 --- a/Pulsator/Pulsator.swift +++ b/Pulsator/Pulsator.swift @@ -24,7 +24,7 @@ public class Pulsator: CAReplicatorLayer { pulse.backgroundColor = backgroundColor let oldAlpha = alpha alpha = CGColorGetAlpha(backgroundColor) - if animationGroup != nil && alpha != oldAlpha { + if alpha != oldAlpha { recreate() } } @@ -83,9 +83,7 @@ public class Pulsator: CAReplicatorLayer { /// The value of this property should be ranging from @c 0 to @c 1 (exclusive). public var keyTimeForHalfOpacity: Float = 0.2 { didSet { - if animationGroup != nil { - recreate() - } + recreate() } } @@ -179,6 +177,7 @@ public class Pulsator: CAReplicatorLayer { // MARK: - Internal Methods internal func recreate() { + guard animationGroup != nil else { return } // Not need to be recreated. stop() let when = dispatch_time(DISPATCH_TIME_NOW, Int64(0.2 * double_t(NSEC_PER_SEC))) dispatch_after(when, dispatch_get_main_queue()) { () -> Void in