1

I'm wondering why there're two types(bounds/frame) for describing a view. Since changing a view's bounds.size.* also changes that view's frame.size.* , and vice versa, this means the only difference lies between frame and bounds is their origin, so why do we need two distinct types for describing view geometry? and by the way what does bounds.origin means exactly?

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
Pwn
  • 3,387
  • 11
  • 38
  • 42
  • possible duplicate of [Why is there an frame rectangle and an bounds rectangle in an UIView?](http://stackoverflow.com/questions/749558/why-is-there-an-frame-rectangle-and-an-bounds-rectangle-in-an-uiview) – jlehr Apr 13 '12 at 19:22

1 Answers1

7

Taken from CocoaDev :

  • The frame is expressed in the coordinate space of a view's superview.
  • The bounds are expressed in a view's own coordinate space.

Visual explanation (by Apple Developer Reference) :

enter image description here

Reference : http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/Concepts/ViewHierarchy.html

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • thanks, but i know the difference between frame/bounds(the question has been updated, sorry), but I'm just wondering why do we need two types for describing views, since the size in both frame/bounds are the same. – Pwn Apr 13 '12 at 18:02
  • 1
    @mf25 Well... let's look at it this way : if ALL we cared about was size, then I suppose apple would have deprecated `bounds` and `frame` and just leave a `width` or `height` property. The reason for the existance of `bounds` & `frame` is that the `NSRect` structure they return (other then `size.width` and `size.height` attributes) includes the starting (X,Y) coordinates. And in that respect, as shown above, they sure differ... :-) – Dr.Kameleon Apr 13 '12 at 18:06
  • 2
    The bounds can be larger and have a different origin than the frame; for example that's how scroll views work. The frame of the scroll view stays fixed while the user moves the bounds. – jlehr Apr 13 '12 at 19:21