Search code examples
iosuiviewcalayer

ios: layer is showed outside its hosting view


I've read the Apple Core Animation document. It says that

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.

But I have a problem about it, showing as the following image: the blue rectangle is a UIView, named blueView, the grey one is a layer which is a sublayer of blueView.layer. The blueView.frame is {0,0}{320,180}. The grey layer's position is {100,190}. Because blueView is hosting the grey layer, I think the grey layer should be showed in the blueView area, because I guess the blueView is the canvas of grey layer. However, the fact is grey layer is showed outside of blueView, why?

enter image description here


Solution

  • For performance reasons by default the "clipsToBounds" properties is set to NO. This means that all the subviews/sublayers are drawn regardless if inside or outside the parent view.