Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the top position = 0 after setStatusBarHidden:Yes?

Tags:

xcode

iphone

I found that after setting the

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]

at viewDidLoad, then if I want to align an image to the top, I will need to set its position as .y = -20;

Is there anyway to make the y coordinate of the top position to 0 ? or is it doomed to be -20 after hidding the status bar?

Thanks for reading.

like image 921
Unreality Avatar asked Feb 06 '09 09:02

Unreality


2 Answers

I had a similar problem at one point and this bit of code fixed it for me:

[viewController.view setFrame: [viewController.view bounds]];
like image 170
Justin Gallagher Avatar answered Oct 20 '22 00:10

Justin Gallagher


Justin Gallagher's solution is almost right, but has one major side effect.

Hiding the status bar and then setting the view's frame to its own bounds will work in the current orientation. But rotation will be ugly. If you are in portrait, for instance, rotating the device to landscape will cause the entire view's frame to be shifted to the right 256 points, leaving a large black space on screen.

bmoeskau's solution (to another side effect) in the comments above avoids this problem:

[self.view setFrame: [[UIScreen mainScreen] bounds]];
like image 30
Steve Cotner Avatar answered Oct 19 '22 23:10

Steve Cotner