CGPoint startPoint = CGPointMake(50, 50);
CGPoint endPoint = CGPointMake(100, 100);
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:startPoint];
[bezierPath addLineToPoint:endPoint];
layer = [CAShapeLayer layer];
//layer.frame = CGRectMake(50, 50, 100, 100);
layer.backgroundColor = [UIColor redColor].CGColor;
layer.path = bezierPath.CGPath;
layer.strokeColor = [UIColor greenColor].CGColor;
layer.fillColor = nil;
[self.view.layer addSublayer:layer];
NSLog(@"%@",NSStringFromCGRect(layer.bounds));
NSLog(@"%@",NSStringFromCGRect(layer.frame));
我得到的日志消息对于帧和绑定都是0,0但是在屏幕上绘制了图层。
我很困惑,尽管在边界和框架上都有0,但是可以在屏幕上绘制图层。我虽然每个视图或图层都需要设置这些属性才能在屏幕上显示。