Merge pull request #8 from basvankuijck/master

Added a `duration` property.
This commit is contained in:
Mike Maxwell
2016-01-27 10:11:58 -08:00
3 changed files with 16 additions and 10 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#
s.name = "MMMaterialDesignSpinner"
s.version = "0.2.2"
s.version = "0.2.3"
s.summary = "An iOS activity spinner modeled after Google's Material Design spinner"
# This description is used to generate tags and improve search results.
@@ -134,4 +134,4 @@ Pod::Spec.new do |s|
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"
end
end
+3
View File
@@ -33,6 +33,9 @@ FOUNDATION_EXPORT const unsigned char MMMaterialDesignSpinnerVersionString[];
/** Property indicating whether the view is currently animating. */
@property (nonatomic, readonly) BOOL isAnimating;
/** Property indicating the duration of the animation, default is 1.5s. Should be set prior to -[startAnimating] */
@property (nonatomic, readwrite) NSTimeInterval duration;
/**
* Convenience function for starting & stopping animation with a boolean variable instead of explicit
* method calls.
+11 -8
View File
@@ -40,6 +40,7 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio
}
- (void)initialize {
self.duration = 1.5f;
_timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer addSublayer:self.progressLayer];
@@ -78,13 +79,15 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio
(animate ? [self startAnimating] : [self stopAnimating]);
}
- (void)startAnimating {
if (self.isAnimating)
return;
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"transform.rotation";
animation.duration = 4.f;
animation.duration = self.duration / 0.375f;
animation.fromValue = @(0.f);
animation.toValue = @(2 * M_PI);
animation.repeatCount = INFINITY;
@@ -93,14 +96,14 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio
CABasicAnimation *headAnimation = [CABasicAnimation animation];
headAnimation.keyPath = @"strokeStart";
headAnimation.duration = 1.f;
headAnimation.duration = self.duration / 1.5f;
headAnimation.fromValue = @(0.f);
headAnimation.toValue = @(0.25f);
headAnimation.timingFunction = self.timingFunction;
CABasicAnimation *tailAnimation = [CABasicAnimation animation];
tailAnimation.keyPath = @"strokeEnd";
tailAnimation.duration = 1.f;
tailAnimation.duration = self.duration / 1.5f;
tailAnimation.fromValue = @(0.f);
tailAnimation.toValue = @(1.f);
tailAnimation.timingFunction = self.timingFunction;
@@ -108,22 +111,22 @@ static NSString *kMMRingRotationAnimationKey = @"mmmaterialdesignspinner.rotatio
CABasicAnimation *endHeadAnimation = [CABasicAnimation animation];
endHeadAnimation.keyPath = @"strokeStart";
endHeadAnimation.beginTime = 1.f;
endHeadAnimation.duration = 0.5f;
endHeadAnimation.beginTime = self.duration / 1.5f;
endHeadAnimation.duration = self.duration / 3.0f;
endHeadAnimation.fromValue = @(0.25f);
endHeadAnimation.toValue = @(1.f);
endHeadAnimation.timingFunction = self.timingFunction;
CABasicAnimation *endTailAnimation = [CABasicAnimation animation];
endTailAnimation.keyPath = @"strokeEnd";
endTailAnimation.beginTime = 1.f;
endTailAnimation.duration = 0.5f;
endTailAnimation.beginTime = self.duration / 1.5f;
endTailAnimation.duration = self.duration / 3.0f;
endTailAnimation.fromValue = @(1.f);
endTailAnimation.toValue = @(1.f);
endTailAnimation.timingFunction = self.timingFunction;
CAAnimationGroup *animations = [CAAnimationGroup animation];
[animations setDuration:1.5f];
[animations setDuration:self.duration];
[animations setAnimations:@[headAnimation, tailAnimation, endHeadAnimation, endTailAnimation]];
animations.repeatCount = INFINITY;
animations.removedOnCompletion = NO;