一個路徑的動畫


- (void)viewDidLoad {

[super viewDidLoad];

self.automaticallyAdjustsScrollViewInsets = NO;

self.view.backgroundColor = [UIColor blackColor];

CAShapeLayer *shapeLayer = ({

CAShapeLayer *shapeLayer = [CAShapeLayer layer];

shapeLayer.path = [self path].CGPath;

shapeLayer.frame = CGRectMake(0, 0, 414, 300);

shapeLayer.fillColor = [UIColor clearColor].CGColor;

shapeLayer.strokeColor = [UIColor whiteColor].CGColor;

shapeLayer.lineWidth = 0.5f;

shapeLayer.opacity = 0.5f;

shapeLayer.position = self.view.center;

[shapeLayer setTransform:CATransform3DMakeScale(1, 1, 1)];

[self.view.layer addSublayer:shapeLayer];

shapeLayer;

});

CAShapeLayer *redLayer = ({

CAShapeLayer *redLayer = [CAShapeLayer layer];

redLayer.frame = CGRectMake(0, 0, 414, 300);

redLayer.path = [self path].CGPath;

redLayer.strokeEnd = 0.f;

redLayer.fillColor = [UIColor clearColor].CGColor;

redLayer.strokeColor = [UIColor redColor].CGColor;

redLayer.lineWidth = 2.f;

redLayer.position = self.view.center;

redLayer.shadowColor = [UIColor redColor].CGColor;

redLayer.shadowOpacity = 1.f;

redLayer.shadowRadius = 4.f;

redLayer.lineCap = kCALineCapRound;

[redLayer setTransform:CATransform3DMakeScale(1, 1, 1.f)];

[self.view.layer addSublayer:redLayer];

CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];

aniStart.fromValue = @0;

aniStart.toValue = @0.98;

CABasicAnimation *aniEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

aniEnd.fromValue = @(0.02);

aniEnd.toValue = @(1);

CAAnimationGroup *group = [CAAnimationGroup animation];

group.duration = 4.f;

group.repeatCount = CGFLOAT_MAX;

group.autoreverses = YES;

group.animations = @[aniEnd,aniStart];

[redLayer addAnimation:group forKey:nil];

redLayer;

});

}

- (UIBezierPath *)path {

return? ({

UIBezierPath *bezierPath = [UIBezierPath bezierPath];

[bezierPath moveToPoint:CGPointMake(0, 150)];

[bezierPath addLineToPoint:CGPointMake(80,10)];

[bezierPath addLineToPoint:CGPointMake(150, 230)];

[bezierPath addLineToPoint:CGPointMake(300, 60)];

[bezierPath addLineToPoint:CGPointMake(400, 280)];

bezierPath;

});

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容