Lê Khánh Vinh Lê Khánh Vinh - 1 year ago 134
iOS Question

UIScreen mainScreen bounds give wrong size

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

Answer Source

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.