Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with frame size of UIView

I'm working on an iPad project, currently it's on Landscape view. And I tried doing:

self.view.frame.size.height

Why is this always returning 960? While as in landscape the height dimension of the view itself should be 768 right?

What I am trying to do is to allocInitWithFrame a UIToolbar that is located at the bottom. The UIToolBar has a height of 50, so here's what I did which failed:

self.bottom_bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.frame.size.height-50, self.view.frame.size.width, 50)];

Why is this and how do I do this?

like image 408
adit Avatar asked Jul 21 '11 02:07

adit


People also ask

What is the correct way to set UIView frame?

1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select "Equal heights". 2)Then go to size inspector of the frame, click edit "Equal height to Superview" constraint, set the multiplier to 0.7 and hit return.

What is frame in UIView?

Frame A view's frame ( CGRect ) is the position of its rectangle in the superview 's coordinate system. By default it starts at the top left. Bounds A view's bounds ( CGRect ) expresses a view rectangle in its own coordinate system.

What is the difference between frame and bound of a UIView?

The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

When should I use layoutSubviews?

layoutSubviews() The system calls this method whenever it needs to recalculate the frames of views, so you should override it when you want to set frames and specify positioning and sizing. However, you should never call this explicitly when your view hierarchy requires a layout refresh.


1 Answers

Two postings (one and two) referenced a similar problem. They both suggest using self.view.bounds instead of self.view.frame.size.width because the bounds change along with the interface orientation.

like image 56
Carter Avatar answered Sep 23 '22 15:09

Carter