畫線動畫
- (void)viewDidLoad{
UIBezierPath *path=[UIBezierPath bezierPath];
[path moveToPoint:CGPointZero];
[path addLineToPoint:CGPointMake(200, 200)];
CAShapeLayer *layer=[CAShapeLayer layer];
layer.fillColor=[UIColor clearColor].CGColor;
layer.strokeColor=[UIColor redColor].CGColor;
layer.path=path.CGPath;
layer.lineWidth = 2;
layer.strokeEnd = 0;
layer.frame=CGRectMake(100, 100, 200, 200);
[self.view.layer addSublayer:layer];
dispatch_async(dispatch_get_main_queue(), ^{
// [CATransaction begin];
// [CATransaction setAnimationDuration:5.0];
layer.strokeEnd=1;
// [CATransaction commit];
});
}
CALayer的Animatable屬性
當設置一個獨立的CALayer(或子類)對象的Animatable屬性時,系統會自動生成隱式動畫;而與UIView關聯的CALayer對象不會生成隱式動畫。隱式動畫可通過CATransaction類管理。