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

后端 未结 3 1430
北海茫月
北海茫月 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:23

    Here's the cheatsheet:

    • frame is where the view is (with respect to the superview)
    • bounds is where the view is allowed to draw (with respect to itself)

    Some more clarification:

    If you are positioning the view in its superview, you almost always change the frame origin.

    If you are clipping where the UIView is drawing, you almost always modify its bounds.

    Note that you are allowed to have bounds that is bigger than the frame. That is, you can draw "outside the lines" of where you are.

提交回复
热议问题