3
votes

Hi i am initiate a rootViewController programatically (portal only no landscape]

this is the code use

CGRect appFrame = [[UIScreen mainScreen] bounds];

But it does not give correct size. (cut down at bottom screen)

Only this code give correct

 CGRect appFrame = [UIScreen mainScreen].applicationFrame

But this code will give warning of depreciated (applicationFrame is depreciated)

(My simulator is IOS 9.3)

How to fix the problem? any help is much appreciate! thanks!

here is screenshoot when using [UIscreen mainscreen].bounds

enter image description here

and here is [UIscreen mainscreen].applicationFrame

enter image description here

3

3 Answers

3
votes

[[UIScreen mainScreen] bounds] gives the correct size of the entire window, but it includes the size of the status bar. If you want the size of the status bar ( you can subtract its height), you should use [[UIApplication sharedApplication] statusBarFrame] to get the frame of the status bar. Navigation bars and tab bars generally have a height of 44. So, use CGRectMake() if you need a rectangle for your view:

CGRect frame_screen = [[UIScreen mainScreen] bounds];
CGRect frame_view = CGRectMake(0,0,frame_screen.size.width,frame_screen.size.height - [[UIApplication sharedApplication] statusBarFrame].size.height);

Notice that the last argument of CGRectMake is the height, usually you can minus 44 for a tab bar or navigation bar.

EDIT: Try to log [UIScreen mainScreen].applicationFrame and [[UIScreen mainScreen] bounds] to console and see what the difference is between them. Something like

CGRect frame_screen = [[UIScreen mainScreen] bounds];
NSLog(@"x: %f, y: %f, width: %f, height: %f",frame_screen.origin.x,frame_screen.origin.y,frame_screen.size.width,frame_screen.size.height);
CGRect frame_application = [UIScreen mainScreen].applicationFrame
NSLog(@"x: %f, y: %f, width: %f, height: %f",frame_application.origin.x,frame_application.origin.y,frame_application.size.width,frame_application.size.height);

Then use that information to make [[UIScreen mainScreen] bounds frame how you need it.

2
votes

you can do the following.

CGRect rect = [UIScreen mainScreen].bounds;

CGRect screenFrame = CGRectMake(0, [[UIApplication sharedApplication] statusBarFrame].size.height, rect.size.width, rect.size.height - [[UIApplication sharedApplication] statusBarFrame].size.height);

Now you can use this screenFrame, I hope this will resolve your problem.

-1
votes

Make sure you have added all resolution splash image on yous's application Images.xcassets `

Please take a look on Screen shot i attached

` enter image description here

CGRect appFrame = [[UIScreen mainScreen] bounds]; //This is the correct way to get your screen size