画线动画
- (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类管理。
网友评论