UIView clipsToBounds property: Does it improve performance?

前端 未结 3 861
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 01:47

The documentation says that the clipsToBounds property of UIView will clip the drawing to the bounds, or more precisely that the subView c

相关标签:
3条回答
  • 2021-02-13 02:16

    The use case for clipsToBounds is more for subviews which are partially outside the main view. For example, I have a (circular) subview on the edge of its parent (rectangular) UIView. If you set clipsToBounds to YES, only half the circle/subview will be shown. If set to NO, the whole circle will show up. Just encountered this so wanted to share.

    0 讨论(0)
  • 2021-02-13 02:18

    The (possible) performance hit is only deterministic if you know the view hierarchy. As mentioned above, usually the renderer will use GPU cycles to draw the view UNLESS some view within the hierarchy uses drawRect:. This does not affect OpenGL ES application because drawRect:is omitted in this type of apps.

    From my understanding, determining and displaying the clipped area may take less cycles than actually calculating/drawing/blending the whole view. As of OpenGL ES 2.0 clipping can be calculated in GPU.

    0 讨论(0)
  • 2021-02-13 02:38

    I think it's the opposite: turning on clipping hurts performance because it has to set up a clipping mask. I vaguely remember reading this somewhere, but I can't find it now.

    0 讨论(0)
提交回复
热议问题