mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
CB-7549 - (Re-fix) [StatusBar][iOS 8] Landscape issue (closes #15)
This commit is contained in:
parent
33674fffd3
commit
5658e7548c
@ -168,10 +168,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
- (void) initializeStatusBarBackgroundView
|
- (void) initializeStatusBarBackgroundView
|
||||||
{
|
{
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation) && !IsAtLeastiOSVersion(@"8.0")) {
|
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
||||||
// swap width and height. set origin to zero
|
|
||||||
statusBarFrame = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.size.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
_statusBarBackgroundView = [[UIView alloc] initWithFrame:statusBarFrame];
|
_statusBarBackgroundView = [[UIView alloc] initWithFrame:statusBarFrame];
|
||||||
_statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor;
|
_statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor;
|
||||||
@ -179,6 +176,19 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
_statusBarBackgroundView.autoresizesSubviews = YES;
|
_statusBarBackgroundView.autoresizesSubviews = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CGRect) invertFrameIfNeeded:(CGRect)rect orientation:(UIInterfaceOrientation)orientation {
|
||||||
|
// landscape is where (width > height). On iOS < 8, we need to invert since frames are
|
||||||
|
// always in Portrait context
|
||||||
|
if (UIDeviceOrientationIsLandscape(orientation) && (rect.size.width < rect.size.height) ) {
|
||||||
|
CGFloat temp = rect.size.width;
|
||||||
|
rect.size.width = rect.size.height;
|
||||||
|
rect.size.height = temp;
|
||||||
|
rect.origin = CGPointZero;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
|
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
|
||||||
{
|
{
|
||||||
// we only care about the latest iOS version or a change in setting
|
// we only care about the latest iOS version or a change in setting
|
||||||
@ -200,18 +210,13 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
|
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
||||||
|
|
||||||
[self initializeStatusBarBackgroundView];
|
[self initializeStatusBarBackgroundView];
|
||||||
|
|
||||||
CGRect frame = self.webView.frame;
|
CGRect frame = self.webView.frame;
|
||||||
|
frame.origin.y = statusBarFrame.size.height;
|
||||||
if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation) && !IsAtLeastiOSVersion(@"8.0")) {
|
frame.size.height -= statusBarFrame.size.height;
|
||||||
frame.origin.y = statusBarFrame.size.width;
|
|
||||||
frame.size.height -= statusBarFrame.size.width;
|
|
||||||
} else {
|
|
||||||
frame.origin.y = statusBarFrame.size.height;
|
|
||||||
frame.size.height -= statusBarFrame.size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.webView.frame = frame;
|
self.webView.frame = frame;
|
||||||
[self.webView.superview addSubview:_statusBarBackgroundView];
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
@ -408,6 +413,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
self.viewController.view.frame = [[UIScreen mainScreen] bounds];
|
self.viewController.view.frame = [[UIScreen mainScreen] bounds];
|
||||||
|
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
|
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
||||||
|
|
||||||
if (!self.statusBarOverlaysWebView) {
|
if (!self.statusBarOverlaysWebView) {
|
||||||
|
|
||||||
@ -415,16 +421,9 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
// from the current one. Therefore we need to expand the statusBarBackgroundView as well to the
|
// from the current one. Therefore we need to expand the statusBarBackgroundView as well to the
|
||||||
// statusBar's current size
|
// statusBar's current size
|
||||||
CGRect sbBgFrame = _statusBarBackgroundView.frame;
|
CGRect sbBgFrame = _statusBarBackgroundView.frame;
|
||||||
|
frame.origin.y = statusBarFrame.size.height;
|
||||||
if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) {
|
frame.size.height -= statusBarFrame.size.height;
|
||||||
frame.origin.y = statusBarFrame.size.width;
|
sbBgFrame.size = statusBarFrame.size;
|
||||||
frame.size.height -= statusBarFrame.size.width;
|
|
||||||
sbBgFrame.size = CGSizeMake(statusBarFrame.size.height, statusBarFrame.size.width);
|
|
||||||
} else {
|
|
||||||
frame.origin.y = statusBarFrame.size.height;
|
|
||||||
frame.size.height -= statusBarFrame.size.height;
|
|
||||||
sbBgFrame.size = statusBarFrame.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
_statusBarBackgroundView.frame = sbBgFrame;
|
_statusBarBackgroundView.frame = sbBgFrame;
|
||||||
[self.webView.superview addSubview:_statusBarBackgroundView];
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
|
Loading…
Reference in New Issue
Block a user