Skip to content

Commit

Permalink
细改
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciusLu committed Jul 29, 2015
1 parent 662e277 commit b153286
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion DeformationButton/DeformationButton/DeformationButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation DeformationButton{
CGFloat defaultR;
CGFloat scale;
UIView *bgView;
UIImage *btnBackgroundImage;
}

- (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor*)color
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +113,10 @@ - (void)loadingAction{
}

- (void)startLoading{
if (btnBackgroundImage == nil) {
btnBackgroundImage = [self.forDisplayButton backgroundImageForState:UIControlStateNormal];
}

_isLoading = YES;

bgView.hidden = NO;
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -165,6 +164,7 @@ - (CAShapeLayer *)progressLayer {
_progressLayer.strokeColor = self.tintColor.CGColor;
_progressLayer.fillColor = nil;
_progressLayer.lineWidth = 1.5f;
// _progressLayer.shouldRasterize = true;
}
return _progressLayer;
}
Expand Down

0 comments on commit b153286

Please sign in to comment.