What's the difference between bounds and frame? In fact, why does 'bounds' even exist? The size of 'bounds' is equal to the frame's size, and the bound's origin should always be 0,0.
-
1Possible duplicate of [Cocoa: What's the difference between the frame and the bounds?](http://stackoverflow.com/questions/1210047/cocoa-whats-the-difference-between-the-frame-and-the-bounds) – daisy May 08 '16 at 03:16
5 Answers
From the View and Window Architecture Programming Guide for iOS:
A view object tracks its size and location using its frame, bounds, and center properties:
The frame property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system.
The bounds property contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.
The center property contains the known center point of the view in the superview’s coordinate system.
Here is a good visualization of that explanation:
-
7Correct. See my question. The bounds would always be 0,0 for the origin, and the sizes are identical. So why have bounds at all then, since frame includes all bound's info anyway? – AWF4vk Dec 13 '11 at 23:04
-
2I have never really looked at this. But is seems clear that you need two references. Because 40,40 would not be right for the origin of the content of the view, but correct for a reference of where the view is within the superview. I would also guess the view needs to know about its own content space (bounds)and give out info of where it should be (Frame). The info may look the same but are actually two different things. Look at them as a views Frame of reference to where it is. And it's Boundaries that shape itself – markhunte Dec 14 '11 at 00:11
-
12While this answer is generally correct, since this is a Mac question (it's tagged `NSView`), the relevant documentation is the [View Programming Guide for Cocoa](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/Introduction/Introduction.html) rather than the iOS version you linked to. Note that on the Mac the coordinate system is flipped by default, with the origin point in the lower-left corner. – Rob Keniger Dec 14 '11 at 03:45
-
7The View itself could be rotated, independent from the frame. In this case, the frame stays the same, but the bounds CGRect gets rotated @David – 11684 Apr 19 '12 at 15:17
-
@David, a view's bounds.size may be different from its frame.size and its origin need not be {0,0}. If the bounds in the example were {10,10,220,360} the image would appear cropped. Apple's [View Programming Guide: View Geometry](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/Coordinates.html) has much better visuals. – Elise van Looij Oct 24 '16 at 13:59
The bound's origin is not always 0,0. It's easy to understand the difference between frame and bounds, if you watch how change bounds property of UIScrollView during scrolling.
For example, you have UIScrollView with frame (0, 0, 320, 460), bounds (0, 0, 320, 460) and ContentSize (640, 460). Its frame always will be (0, 0, 320, 460), but the X coordinate of bounds will change depending on distance of scrolling.
It can be useful if you want to change something in you UIScrollView (create and remove pages diynamically for example), so you want to know distance of scrolling.
The apple documents in the first answer don't cover what happens to the frame and the bounds after rotating to landscape orientation. So to be more complete, you should know that the frame of the window and the root view does not change after rotation, but the bounds do. See this article for a a little more detail and be careful using frame as a reference for anything other than portrait orientation.
From the article:
If your view controller has the top-level non-window view (i.e., it’s the bottom-most view controller), then
self.frame
is always in portrait orientation. Wha? Yes, always in portrait – what changes is the transform of your view. So your
self.bounds
is always accurate (keeping in mind the last point), but
self.frame
may or may not give the aspect ratio that the user is really seeing, since each view’s frame is reported in terms of the superview’s coordinates, and takes into account any transforms applied to the view.
A views frame is the size of a rectangle it can completely fit into. It always seems as if the bounds and the frame are same but that's not the case. Consider a square which is just rotated about 45 degrees!
Here the frame of the this rotated square will be the rectangle to completely fill it in and so it will differ from the bounds of this object.
P.S mostly in rotated objects frames and bounds tend to differ.

- 288
- 2
- 11
frame is coordinates values in the super view's coordinate system
bounds is used by the drawing system to draw the view's content, when the drawing is done, the system will use a transform operation to assign the content to the view's frame

- 695
- 7
- 10