【发布时间】:2012-03-13 18:35:10
【问题描述】:
我正在尝试添加一个 CALayer 作为另一个 CALayer 的子层。然而,只有父层被显示。这是我的代码:
//display a green square:
CALayer *shipContainer = [CALayer layer];
shipContainer.bounds = CGRectMake(0,0,200,200);
shipContainer.position = CGPointMake(600,500);
shipContainer.borderColor = [UIColor greenColor].CGColor;
shipContainer.borderWidth = 3;
//display a red dot inside the square:
CALayer *ship1 = [CALayer layer];
ship1.bounds = CGRectMake(0,0,20,20);
ship1.position = CGPointMake(600,500);
ship1.cornerRadius = 10;
ship1.backgroundColor = [UIColor redColor].CGColor;
[shipContainer addSublayer:ship1];
然后我调用[self.view.layer addSublayer:shipContainer];,但只显示绿色方块。有什么想法吗?
【问题讨论】:
标签: iphone objective-c cocoa-touch core-animation