9
votes

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

4
If you use auto layout, check if you set proper constraint to make the view auto resize according to the screen size else check if you set the right autoResizingMask.Danyun Liu
Hi, thanks for answer. I was able to resolve issue when i create view controller programatically (i had to clear derived data, and clean product) but now I need to get the autolayout in XIB to work properly. I was looking into the constraints, but it seems to me i can define constraints only for child views, but not for main view controller's view. How do you set the constraints for autoresizing according to the screen?r2d2
this guide will help you to support both ios 6 and ios 7 , developer.apple.com/library/ios/documentation/userexperience/…Danyun Liu
agree, this problem is infuriating. in a somewhat similar situation, this saved the day .. - (void)viewWillLayoutSubviews { // horrible fix, to make it position properly on all (most?? many??) devices! self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0); }Fattie

4 Answers

1
votes

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).

enter image description here

1
votes

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.

1
votes

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)

0
votes

I had a similar problem. Turns out that I had a embeded segue and that the original container view was hard coded to 568:

Here

I am not sure if this will solve your problem, but something to look out for.