Gibson
Gibson

Reputation: 810

iOS: How can I figure out the size of the view in the super view's layout?

views screenshot

When I use self.view.frame.size.height, it gets the height of the child nib, rather than the height of how the view is going to fit into the overall layout. I get the same value using self.view.bounds.size.height and super.view.bounds.size.height.

Any help would be appreciated.

Upvotes: 0

Views: 173

Answers (2)

Mr. Berna
Mr. Berna

Reputation: 10655

Ask at the right time. Not until the view is ready to appear has iOS figured out what size it will actually be. Move your code that depends upon the view being the right size to viewWillAppear instead of viewDidLoad or an init method.

Upvotes: 2

Robin Summerhill
Robin Summerhill

Reputation: 13675

In Xcode 4 you would select your view controller that contains the UIScrollView and set the 'Simulated Metrics' in the IB Attributes Inspector as follows:

Attributes Inspector

This ensures that your UIScrollView will be set to the correct size to fill the available space at design time. It looks like you are using an older version of Xcode/IB and I can't remember exactly where these settings used to be but they're in there somewhere.

With the layout designed to accommodate the space taken up by the tab bar you should be able to query the size of the UIScrollView at any time and get the correct values.

Upvotes: 0

Related Questions