2012-03-13 76 views
1

我试图添加一个CALayer作为另一个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];,但只显示绿色广场。有什么想法吗?

回答

1

作为每documentation

位置

位置属性是一个CGPoint,指定相对于其superlayer所述 层的位置,且superlayer的 坐标系中被表达。

,所以你需要改变

ship1.position = CGPointMake(600,500); 

使ship1可以进来可见区域。由于超级玩家拥有200,200作为界限,因此您需要使位置的xy少于这些值。

+0

正确!谢谢你的帮助! – Eric 2012-03-13 18:52:52