(iOS) Fix for status bar show/hide errors while rotating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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