diff --git a/DeformationButton/DeformationButton/DeformationButton.m b/DeformationButton/DeformationButton/DeformationButton.m index 73db78b..91fae62 100644 --- a/DeformationButton/DeformationButton/DeformationButton.m +++ b/DeformationButton/DeformationButton/DeformationButton.m @@ -14,6 +14,7 @@ @implementation DeformationButton{ CGFloat defaultR; CGFloat scale; UIView *bgView; + UIImage *btnBackgroundImage; } - (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor*)color @@ -57,6 +58,7 @@ - (void)initSettingWithColor:(UIColor*)color{ bgView.backgroundColor = color; bgView.userInteractionEnabled = NO; bgView.hidden = YES; + bgView.layer.cornerRadius = 3; [self addSubview:bgView]; defaultW = bgView.frame.size.width; @@ -111,6 +113,10 @@ - (void)loadingAction{ } - (void)startLoading{ + if (btnBackgroundImage == nil) { + btnBackgroundImage = [self.forDisplayButton backgroundImageForState:UIControlStateNormal]; + } + _isLoading = YES; bgView.hidden = NO; @@ -119,10 +125,12 @@ - (void)startLoading{ animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; animation.fromValue = [NSNumber numberWithFloat:defaultR]; animation.toValue = [NSNumber numberWithFloat:defaultH*scale*0.5]; - animation.duration = 0.2; + animation.duration = 0.3; [bgView.layer setCornerRadius:defaultH*scale*0.5]; [bgView.layer addAnimation:animation forKey:@"cornerRadius"]; + [self.forDisplayButton setBackgroundImage:nil forState:UIControlStateNormal]; + [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ bgView.layer.bounds = CGRectMake(0, 0, defaultW*scale, defaultH*scale); } completion:^(BOOL finished) { @@ -148,6 +156,14 @@ - (void)stopLoading{ } completion:^(BOOL finished) { }]; + CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"]; + animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; + animation.fromValue = [NSNumber numberWithFloat:defaultH*scale*0.5]; + animation.toValue = [NSNumber numberWithFloat:defaultR]; + animation.duration = 0.3; + [bgView.layer setCornerRadius:defaultR]; + [bgView.layer addAnimation:animation forKey:@"cornerRadius"]; + [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ bgView.layer.bounds = CGRectMake(0, 0, defaultW*scale, defaultH*scale); } completion:^(BOOL finished) { @@ -161,6 +177,9 @@ - (void)stopLoading{ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ bgView.layer.bounds = CGRectMake(0, 0, defaultW, defaultH); } completion:^(BOOL finished) { + if (btnBackgroundImage != nil) { + [self.forDisplayButton setBackgroundImage:btnBackgroundImage forState:UIControlStateNormal]; + } bgView.hidden = YES; _isLoading = NO; }]; diff --git a/DeformationButton/DeformationButton/MMMaterialDesignSpinner-master/MMMaterialDesignSpinner.m b/DeformationButton/DeformationButton/MMMaterialDesignSpinner-master/MMMaterialDesignSpinner.m index a2ed351..68aeb78 100755 --- a/DeformationButton/DeformationButton/MMMaterialDesignSpinner-master/MMMaterialDesignSpinner.m +++ b/DeformationButton/DeformationButton/MMMaterialDesignSpinner-master/MMMaterialDesignSpinner.m @@ -36,7 +36,6 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { - (void)initialize { _timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; - [self.layer addSublayer:self.progressLayer]; // See comment in resetAnimations on why this notification is used. @@ -165,6 +164,7 @@ - (CAShapeLayer *)progressLayer { _progressLayer.strokeColor = self.tintColor.CGColor; _progressLayer.fillColor = nil; _progressLayer.lineWidth = 1.5f; +// _progressLayer.shouldRasterize = true; } return _progressLayer; }