Why is there an frame rectangle and an bounds rectangle in an UIView?

后端 未结 3 1428
北海茫月
北海茫月 2020-12-02 06:48

Well although it\'s late in the dark night, I don\'t get it why there are two different rectangles: frame and bounds.

Like I understand it, one single rectangle wou

3条回答
  •  佛祖请我去吃肉
    2020-12-02 07:01

    I've been having troubles with bounds lately and have done some experimentation. The bounds property does limit where a UIView can draw, but does not limit its subviews. The other thing bounds controls is touch event dispatching. A view will not, as far a I can tell, receive touch events that are outside its bounds. Furthermore, any subview that outside of the parent view's bounds will also not receive touch events. In these situations, you have to pretty meticulously update the bounds of the container view as the size and position of its subviews change. Everything will always draw fine (because subviews aren't clipped by the bounds of their parent) but touches won't be received.

    (This really should be a reply to an earlier post, but since I can't reply yet, it's stuck here...)

提交回复
热议问题