2013-01-06 29 views
1

我加入一个CALayer作为子层的UIViewlayer属性,如下所示:将子图层添加到view.layer会更改帧的位置?

_graphicLayer = [[GraphicLayer alloc] init]; 
     self.bounds = _graphicLayer.bounds; 
     _graphicLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); 
     [self.layer addSublayer:_graphicLayer]; 

正如你所看到的,我改变位置_ graphicLayer占居中anchorPoint。我注意到添加了这个子图层后,它将视图frame更改为(-self.bounds.width/2, -self.bounds.height/2)。这是为什么发生?如果我改变_ graphicLayer的位置,我认为这只是相对于其父视图。为什么会影响frame属性的意见? (我不想调整视图图层属性或_graphicLayer的anchorPoint)。

回答

2

你目前做

self.bounds = _graphicLayer.bounds; 

这将改变视图的(自我的)框架,因为它会改变的宽度和高度。也许你的意思做:

_graphicLayer.bounds = self.bounds; 

在这里看到有关边界如何影响框架:Link

相关问题