in iOS controls we have frames and bounds. Frames coordination system is relative to its parent and bounds coordination system is relative to itself. But why iOS distinct coordination system to this two version?
1 Answers
The width and the height of the view is the same regardless of whether we are looking at the bounds or frame. The difference is the x,y positioning of the view. In the case of the bounds, the x and y coordinates are at 0,0 as these coordinates are relative to the view itself. However, the frame x and y coordinates are relative to the position of the view within the parent view.
If you are getting the same results for both properties, it means that the view fills its superview, and both views have (0, 0) as the origin. Try changing the frame, and you will see it move to different positions within its superview.
A view’s bounds describes the view’s location and size in its own coordinate system while its frame describes the view’s location and size in its superview’s coordinate system.Thus root view controller’s view’s frame is in the window’s coordinate system. A noteworthy characteristic of UIWindow is that its coordinate system is always in portrait orientation. As such, the root view controller’s view’s frame will not properly respect interface orientation changes, but its bounds will. Therefore, you should always perform layout calculations using your view controller’s view’s bounds size, as opposed to its frame size.
http://cocoa.tumblr.com/post/43021164010/an-important-difference-between-frame-and-bounds
-
Yeah, you are right but what is purpose of distinct for frames and bounds. Cant we use only frame? In what cases we should use bounds? – Sayaki Sep 30 '14 at 08:42