ios:图层显示在其托管视图之外

时间:2012-11-23 16:06:33

标签: ios uiview calayer

我已阅读Apple Core动画文档。它说

Core Animation doesn't provide a means for actually displaying layers in a window, they must be hosted by a view. When paired with a view, the view must provide event-handling for the underlying layers, while the layers provide display of the content.

但是我有一个问题,如下图所示:蓝色矩形是UIView,名为blueView,灰色矩形是一个层,它是blueView.layer的子层。 blueView.frame是{0,0} {320,180}。灰色层的位置是{100,190}。因为blueView托管灰色层,我认为灰色层应该显示在blueView区域,因为我猜blueView是灰色层的画布。但是,事实是在blueView之外显示灰色层,为什么?

enter image description here

1 个答案:

答案 0 :(得分:3)

出于性能原因,默认情况下“clipsToBounds”属性设置为NO。这意味着无论是在父视图的内部还是外部,都会绘制所有子视图/子图层。