IOS4 note 15 (3) Frame

Frame

A view’s frame property, a CGRect, is the position of its rectangle within its superview, in the superview’s coordinate system. By default, the superview’s coordinate system will have the origin at the top left, with the x-coordinate growing positively rightward and the y-coordinate growing positively downward.

Setting a view’s frame to a different CGRect value repositions the view, or resizes it, or both. If the view is visible, this change will be visibly reflected in the interface. On the other hand, you can also set a view’s frame when the view is not visible — for example, when you create the view in code. In that case, the frame describes where the frame will be positioned within its superview when it is assigned a superview. UIView’s designated initializer is initWithFrame:, and you’ll often assign a frame this way, especially because the default frame might otherwise be (0,0,0,0), which is rarely what you want.

A view with a zero-size frame is effectively invisible. If a view has a standard size that you want it to adopt, especially in  relation  to  its contents  (like a UIButton  in  relation  to  its  title), an alternative is to send it the sizeToFit message.

Part of the app’s window may be covered by the status bar, which is actually another window, supplied by the system. This may affect where you want to draw in the window. A view centered within the window will be centered on the screen, but it may not look centered because it isn’t centered in the visible part of the window (exclusive of the  status bar). Similarly, material drawn  in  the window  at  the point  (0,0)  (in  the window’s coordinates) may not be visible, because that point may be covered by the status bar. You can determine the rectangle currently not covered by the status bar as follows:

CGRect f = [[UIScreen mainScreen] applicationFrame];

 

 

你可能感兴趣的:(IOS4 note 15 (3) Frame)