Wednesday, January 28, 2015

Whats the difference between frame and bounds?

All UIViews have frame and bounds properties which define their dimensions.
The frame of a view is given in the coordinates of its superview so a view controller’s view’s frame will include offsets for the status bar, navigation bar, or tab bar. The bounds of a view are given in the view’s own coordinate system which does not include these elements.

In addition the frame property’s values are undefined if the view has any transform other than the identity transform. Rotating a view into landscape mode applies a transform to the view so it is not safe to rely on frame values for an app in landscape mode.
The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed in its own coordinate system (0,0). Frame's size and bound's size are always same/equal. 
Center A center is a CGPoint expressed in terms of the superview's coordinate system and it determines the position of the exact center point of the view.
Using the frame allows you to reposition and/or resize a view within its superview.
When you need the coordinates to drawing inside a view you usually refer to bounds.
A typical example could be to draw within a view a subview as an inset of the first. Drawing the subview requires to know the bounds of the superview.
Different behaviours happen when you change the bounds of a view. For example, if you change thebounds size, the frame changes (and vice versa). The change happens around the center of the view.

0 comments:

Post a Comment

About

Blog Archive

Powered by Blogger.

Blog Archive