tags:

views:

2812

answers:

2

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 enoug 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 eachother?

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

+2  A: 

Frame is in the superview's coordinate system, bounds is in the view's coordinate system. From my perspective, it is a convenience to have both. Frame seems to be the more useful of the two, unless there is some case I am unaware of where a subview can have a completely different coordinate system (e.g. pixels scaled differently) than the superview.

Travis Jensen
+13  A: 

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.

Kailoa Kadano
so the frame is something like a starting coordinate relative to the superview coordinate system, and from that starting point the bounds clipping will be done in coordinates relative to the view coordinate system?
Thanks