Reputation: 111
I'm really struggling with this one. I searched this issue all over but no one seems to experience exactly the same problem.
So I have this ios7 project, which should run on both 4 and 3.5 inch devices. On 4 inch, everything is fine, but on 3.5 inch view controllers have frames height of 568
If i log the UIScreen bounds in AppDelegate, it returns correctly 480. But if i create UIViewController and add it as rootViewController to NavigationController, its height is 568. (NavigationController has too a proper height of 480)
First, I thought it may be because of XIB, so i created blank UIViewController just by [[UIViewController alloc] init], but it still has height of 568.
This is driving me crazy, because my other project works fine this way and viewcontrollers are resized automatically.
I checked i have a proper starting images defined in images.xcassets, and i tried XIB both with and without autolayout.
Only one thing helped, if i turn simulated metrics in xib to NONE or 3.5 inch, but then i dont get fullcreen on 4 inch. And having multiple xib for both screens is not solution for me.
Any hint would be greatly appreciated
Thanks
Upvotes: 9
Views: 2821
Reputation: 2916
YOU get the size in wrong timing.
The initialized size is from NIB,
SO you need get the adjusted size in -viewDidLayoutSubviews
(lower version in -viewDidAppear
)
Upvotes: 1
Reputation: 1234
I had a similar problem. Turns out that I had a embeded segue and that the original container view was hard coded to 568:
I am not sure if this will solve your problem, but something to look out for.
Upvotes: 0
Reputation: 24247
This happened to me except it was the other way around - the app ran on the 4 inch with a 3.5 inch screen.
The trick is your launch images. Make sure that your R4 image is actually for the 4 inch and the @2X Image is for the 3.5 inch.
Upvotes: 1
Reputation: 31
I was currently facing this problem as i am using the autoLayouts but now I have resolved this issue using nib. So i want to share it with you.
If you are making a viewController through nib. Then you should make sure that "Resize View From NIB" is checked . After doing this you will get the frame height of the view w.r.t screen bounds. ( in 3.5 inch screen it will be 480 and in 4 inch it will be 568).
Upvotes: 1