From 045ee21f6a8a924c02827eccd63499fa92dd1372 Mon Sep 17 00:00:00 2001 From: shu223 Date: Sun, 15 Jan 2017 17:52:35 -0800 Subject: [PATCH] added a property to disable resume --- PulsingHalo/PulsingHaloLayer.h | 6 ++++++ PulsingHalo/PulsingHaloLayer.m | 23 +++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/PulsingHalo/PulsingHaloLayer.h b/PulsingHalo/PulsingHaloLayer.h index 733d09f..0fac2d5 100644 --- a/PulsingHalo/PulsingHaloLayer.h +++ b/PulsingHalo/PulsingHaloLayer.h @@ -67,6 +67,12 @@ */ @property (nonatomic, assign) NSTimeInterval startInterval; +/** + * When this value is true, the halo will be automatically resumed after entering foreground. + * + * The default value of this property is YES. + */ +@property (nonatomic, assign) BOOL shouldResume; - (void)start; diff --git a/PulsingHalo/PulsingHaloLayer.m b/PulsingHalo/PulsingHaloLayer.m index d309fb0..dcf6dd3 100644 --- a/PulsingHalo/PulsingHaloLayer.m +++ b/PulsingHalo/PulsingHaloLayer.m @@ -70,11 +70,8 @@ - (void)onDidEnterBackground:(NSNotification *)notification { } - (void)onWillEnterForeground:(NSNotification *)notification { - NSLog(@"effect:%@, superlayer:%@, effect.superlayer:%@", self.effect, self.superlayer, self.effect.superlayer); - [self addSublayer:self.effect]; - [self.prevSuperlayer insertSublayer:self atIndex:self.prevLayerIndex]; - if (self.prevAnimation) { - [self.effect addAnimation:self.prevAnimation forKey:@"pulse"]; + if (self.shouldResume) { + [self _resume]; } } @@ -97,7 +94,6 @@ - (void)setBackgroundColor:(CGColorRef)backgroundColor { } - (void)setRadius:(CGFloat)radius { - _radius = radius; CGFloat diameter = self.radius * 2; @@ -107,7 +103,6 @@ - (void)setRadius:(CGFloat)radius { } - (void)setPulseInterval:(NSTimeInterval)pulseInterval { - _pulseInterval = pulseInterval; if (_pulseInterval == INFINITY) { @@ -116,20 +111,17 @@ - (void)setPulseInterval:(NSTimeInterval)pulseInterval { } - (void)setHaloLayerNumber:(NSInteger)haloLayerNumber { - _haloLayerNumber = haloLayerNumber; self.instanceCount = haloLayerNumber; self.instanceDelay = (self.animationDuration + self.pulseInterval) / haloLayerNumber; } - (void)setStartInterval:(NSTimeInterval)startInterval { - _startInterval = startInterval; self.instanceDelay = startInterval; } - (void)setAnimationDuration:(NSTimeInterval)animationDuration { - _animationDuration = animationDuration; self.instanceDelay = (self.animationDuration + self.pulseInterval) / self.haloLayerNumber; @@ -145,6 +137,7 @@ - (void)setRepeatCount:(float)repeatCount { #pragma mark - Private - (void)_setupDefaults { + _shouldResume = YES; _fromValueForRadius = 0.0; _keyTimeForHalfOpacity = 0.2; _animationDuration = 3; @@ -159,7 +152,6 @@ - (void)_setupDefaults { } - (void)_setupAnimationGroup { - CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; animationGroup.duration = self.animationDuration + self.pulseInterval; animationGroup.repeatCount = self.repeatCount; @@ -187,12 +179,19 @@ - (void)_setupAnimationGroup { self.animationGroup.delegate = self; } +- (void)_resume { + [self addSublayer:self.effect]; + [self.prevSuperlayer insertSublayer:self atIndex:self.prevLayerIndex]; + if (self.prevAnimation) { + [self.effect addAnimation:self.prevAnimation forKey:@"pulse"]; + } +} + // ============================================================================= #pragma mark - CAAnimationDelegate - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { - if ([self.effect.animationKeys count]) { [self.effect removeAllAnimations]; }