#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CAShapeLayer *bottomLayer = [CAShapeLayer layer];
bottomLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:100].CGPath;
bottomLayer.backgroundColor = [UIColor orangeColor].CGColor;
bottomLayer.lineWidth = 5;
bottomLayer.fillColor = [UIColor whiteColor].CGColor;
bottomLayer.strokeColor = [UIColor purpleColor].CGColor;
[self.view.layer addSublayer:bottomLayer];
CAShapeLayer *ovalShaper = [CAShapeLayer layer];
ovalShaper.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 100, 100)].CGPath;
ovalShaper.lineCap = kCALineCapRound;
ovalShaper.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:100].CGPath;
ovalShaper.fillColor = [UIColor whiteColor].CGColor;
ovalShaper.strokeColor = [UIColor redColor].CGColor;
ovalShaper.lineWidth = 5;
[self.view.layer addSublayer:ovalShaper];
CABasicAnimation *startAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
startAnimation.fromValue = @(-1);
startAnimation.toValue = @(1.0);
CABasicAnimation *endAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
endAnimation.fromValue = @(0.0);
endAnimation.toValue = @(1);
//组合动画
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[startAnimation,endAnimation];
group.duration = 1;
group.repeatCount = CGFLOAT_MAX;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[ovalShaper addAnimation:group forKey:nil];
}
@end
网友评论