Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix status bar position problem on iPad with iOS version 9 (and above) #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 63 additions & 18 deletions MTStatusBarOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
#pragma mark -
#pragma mark Defines
////////////////////////////////////////////////////////////////////////

// macro to check if running on at least iOS 9
#define kMTIsOperatingSystemAtLeast9 [[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] ? [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9.0, 0.0, 0.0}] : NO
#define kMTIsOperatingSystemAtLeast91 [[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] ? [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9.0, 1.0, 0.0}] : NO
#define kMTIsOperatingSystemAtLeast92 [[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] ? [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9.0, 2.0, 0.0}] : NO
// macro to check if running on at least iOS 8
#define kMTIsOperatingSystemAtLeast8 [[NSProcessInfo processInfo] respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] ? [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){8.0, 0.0, 0.0}] : NO
// the height of the status bar
Expand Down Expand Up @@ -874,24 +877,66 @@ - (void)rotateToStatusBarFrame:(NSValue *)statusBarFrameValue {
[self setDetailViewHidden:YES animated:NO];
}

// fix status bar position problem on iPad with iOS version 9
CGFloat pi = (CGFloat)M_PI;
if (orientation == UIDeviceOrientationPortrait) {
self.transform = CGAffineTransformIdentity;
self.frame = CGRectMake(0.f,0.f,kScreenWidth,kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.0f, kWidthSmall, self.frame.size.height);
}else if (orientation == UIDeviceOrientationLandscapeLeft) {
self.transform = CGAffineTransformMakeRotation(pi * (90.f) / 180.0f);
self.frame = CGRectMake(kScreenWidth - kStatusBarHeight,0, kStatusBarHeight, kScreenHeight);
self.smallFrame = CGRectMake(kScreenHeight-kWidthSmall,0,kWidthSmall,kStatusBarHeight);
} else if (orientation == UIDeviceOrientationLandscapeRight) {
self.transform = CGAffineTransformMakeRotation(pi * (-90.f) / 180.0f);
self.frame = CGRectMake(0.f,0.f, kStatusBarHeight, kScreenHeight);
self.smallFrame = CGRectMake(kScreenHeight-kWidthSmall,0.f, kWidthSmall, kStatusBarHeight);
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
self.transform = CGAffineTransformMakeRotation(pi);
self.frame = CGRectMake(0.f,kScreenHeight - kStatusBarHeight,kScreenWidth,kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.f, kWidthSmall, self.frame.size.height);
}
if (orientation == UIDeviceOrientationPortrait) {
self.transform = CGAffineTransformIdentity;
if ((BOOL) (kMTIsOperatingSystemAtLeast9)) {
self.frame = CGRectMake(0.f, 0.f, MIN(kScreenWidth, kScreenHeight), kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.0f, kWidthSmall, self.frame.size.height);
} else {
self.frame = CGRectMake(0.f, 0.f, kScreenWidth, kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.0f, kWidthSmall, self.frame.size.height);
}
} else if (orientation == UIDeviceOrientationLandscapeLeft) {
if ((BOOL) (kMTIsOperatingSystemAtLeast9)) {
if ((BOOL) (kMTIsOperatingSystemAtLeast91) && !(BOOL)(kMTIsOperatingSystemAtLeast92)) {
self.transform = CGAffineTransformMakeRotation(pi * (90.f) / 180.0f);
self.frame = CGRectMake(kScreenWidth - kStatusBarHeight, 0, kStatusBarHeight, kScreenHeight);
self.smallFrame = CGRectMake(MAX(kScreenHeight, kScreenWidth) - kWidthSmall, 0, kWidthSmall, kStatusBarHeight);
} else {
self.transform = CGAffineTransformIdentity;
self.frame = CGRectMake(0, 0, MAX(kScreenHeight, kScreenWidth), kScreenHeight);
self.smallFrame = CGRectMake(MAX(kScreenHeight, kScreenWidth) - kWidthSmall, 0, kWidthSmall, kStatusBarHeight);
}
} else {
self.transform = CGAffineTransformMakeRotation(pi * (90.f) / 180.0f);
self.frame = CGRectMake(kScreenWidth - kStatusBarHeight, 0, kStatusBarHeight, kScreenHeight);
self.smallFrame = CGRectMake(kScreenHeight - kWidthSmall, 0, kWidthSmall, kStatusBarHeight);
}
} else if (orientation == UIDeviceOrientationLandscapeRight) {
if ((BOOL) (kMTIsOperatingSystemAtLeast9)) {
if ((BOOL) (kMTIsOperatingSystemAtLeast91) && !(BOOL)(kMTIsOperatingSystemAtLeast92)) {
self.transform = CGAffineTransformMakeRotation(pi * (-90.f) / 180.0f);
self.frame = CGRectMake(0, 0, MAX(kScreenHeight, kScreenWidth), kScreenHeight);
self.smallFrame = CGRectMake(MAX(kScreenHeight, kScreenWidth) - kWidthSmall, 0.f, kWidthSmall, kStatusBarHeight);
} else {
self.transform = CGAffineTransformIdentity;
self.frame = CGRectMake(0, 0, MAX(kScreenHeight, kScreenWidth), kScreenHeight);
self.smallFrame = CGRectMake(MAX(kScreenHeight, kScreenWidth) - kWidthSmall, 0.f, kWidthSmall, kStatusBarHeight);
}
} else {
self.transform = CGAffineTransformMakeRotation(pi * (-90.f) / 180.0f);
self.frame = CGRectMake(0.f, 0.f, kStatusBarHeight, kScreenHeight);
self.smallFrame = CGRectMake(kScreenHeight - kWidthSmall, 0.f, kWidthSmall, kStatusBarHeight);
}
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
if ((BOOL) (kMTIsOperatingSystemAtLeast9)) {
if ((BOOL) (kMTIsOperatingSystemAtLeast91) && !(BOOL)(kMTIsOperatingSystemAtLeast92)) {
self.transform = CGAffineTransformMakeRotation(pi);
self.frame = CGRectMake(0.f, kScreenHeight - kStatusBarHeight, MIN(kScreenWidth, kScreenHeight), kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.f, kWidthSmall, self.frame.size.height);
} else {
self.transform = CGAffineTransformIdentity;
self.frame = CGRectMake(0.f, 0.f, MIN(kScreenWidth, kScreenHeight), kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.f, kWidthSmall, self.frame.size.height);
}
} else {
self.transform = CGAffineTransformMakeRotation(pi);
self.frame = CGRectMake(0.f, kScreenHeight - kStatusBarHeight, kScreenWidth, kStatusBarHeight);
self.smallFrame = CGRectMake(self.frame.size.width - kWidthSmall, 0.f, kWidthSmall, self.frame.size.height);
}
}

self.backgroundView.frame = [self backgroundViewFrameForStatusBarInterfaceOrientation];

Expand Down