Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created June 6, 2012 12:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rsaunders100/ce4f0cbbc84494c9b586 to your computer and use it in GitHub Desktop.
(iOS) Fix for status bar show/hide errors while rotating
/*
This should be called after [[UIApplication sharedApplication] setStatusBarHidden:
This is a bug (with iOS) replicated by doing the following:
1) Hide the status bar
2) Swap the orentation (either to portrait or landscape)
3) Show the status bar
This is a really shity hack to fix the issue
based on logging the frame under normal and error conditions
This fix *should* port to iPad too since there is no reference to absloute dimensions,
Noramal conditions (status bar showing)
Port: {0, 20}, {320, 460}
Land: {0, 0}, {300, 460}
Error conditions (status bar showing)
Port: {0, 0}, {320, 480}
Land: {0, 0}, {320, 480}
As you can see there is no logical patten or consistancy to this
This code just dectects error conditions and switches to Normal conditons
*/
- (void) correctStatusbarErrors
{
BOOL statusBarVisible = ![[UIApplication sharedApplication] isStatusBarHidden];
if (statusBarVisible)
{
CGSize viewSize = self.view.frame.size;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
float statusbarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
float statusbarWidth = [[UIApplication sharedApplication] statusBarFrame].size.width;
float statusbarDistanceFromTop = MIN(statusbarHeight, statusbarWidth);
if (self.view.frame.origin.y == 0 &&
viewSize.height == screenSize.height &&
viewSize.width == screenSize.width)
{
CGRect frame = self.view.frame;
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
// For some reason in landscape we dont need to offset the origin!
//frame.origin.x = statusbarDistanceFromTop;
frame.size.width = screenSize.width - statusbarDistanceFromTop;
}
else
{
frame.origin.y = statusbarDistanceFromTop;
frame.size.height = screenSize.height - statusbarDistanceFromTop;
}
self.view.frame = frame;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment