Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

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

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 would have been just enough to do everything. Positioning the View itself relative to another coordinate system, and then clipping it's content to a specified size. What else would you do with two rectangles? And how do they interact with each other?

Does anyone have a good explanation? The one from the Apple docs with the kid holding the fruit is not very good for understanding.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...