我对 CALayer 的属性范围感到困惑,
- (void)viewDidLoad {
[super viewDidLoad];
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.frame = CGRectMake(18, 18, 154, 154);
[self.view.layer addSublayer:sublayer];
CALayer *sublayer2 = [CALayer layer];
sublayer2.backgroundColor = [UIColor redColor].CGColor;
sublayer2.frame = CGRectMake(20, 20, 150, 150);
sublayer2.bounds = CGRectMake(0, 0, 50, 50);
sublayer2.zPosition = 10;
[self.view.layer addSublayer:sublayer2];
}
sublayer2 在 sublayer1 的矩形中心绘制一个 50X50 的小矩形,但是如果注释掉这条线,它会绘制一个 150X150 的矩形:
sublayer2.bounds = CGRectMake(0, 0, 50, 50);