将子图层添加到view.layer更改框架位置?

时间:2013-01-06 05:50:41

标签: iphone ios cocoa-touch core-animation calayer

我正在将CALayer作为子图层添加到UIView的{​​{1}}属性中,如下所示:

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)的anchorPoint。

1 个答案:

答案 0 :(得分:2)

你现在正在做

self.bounds = _graphicLayer.bounds;

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

_graphicLayer.bounds = self.bounds;

请在此处查看边界如何影响框架:Link

相关问题