From 5658e7548c813bf7d6102eea4eaa7726b727b18e Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Mon, 6 Oct 2014 14:43:12 -0700 Subject: [PATCH] CB-7549 - (Re-fix) [StatusBar][iOS 8] Landscape issue (closes #15) --- src/ios/CDVStatusBar.m | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index e39424d..f305f63 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -168,10 +168,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle; - (void) initializeStatusBarBackgroundView { CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; - if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation) && !IsAtLeastiOSVersion(@"8.0")) { - // swap width and height. set origin to zero - statusBarFrame = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.size.width); - } + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; _statusBarBackgroundView = [[UIView alloc] initWithFrame:statusBarFrame]; _statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor; @@ -179,6 +176,19 @@ static const void *kStatusBarStyle = &kStatusBarStyle; _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 { // we only care about the latest iOS version or a change in setting @@ -200,18 +210,13 @@ static const void *kStatusBarStyle = &kStatusBarStyle; } else { CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; [self initializeStatusBarBackgroundView]; CGRect frame = self.webView.frame; - - if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation) && !IsAtLeastiOSVersion(@"8.0")) { - 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; - } + frame.origin.y = statusBarFrame.size.height; + frame.size.height -= statusBarFrame.size.height; self.webView.frame = frame; [self.webView.superview addSubview:_statusBarBackgroundView]; @@ -408,6 +413,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle; self.viewController.view.frame = [[UIScreen mainScreen] bounds]; CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; 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 // statusBar's current size CGRect sbBgFrame = _statusBarBackgroundView.frame; - - if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) { - frame.origin.y = statusBarFrame.size.width; - 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; - } + frame.origin.y = statusBarFrame.size.height; + frame.size.height -= statusBarFrame.size.height; + sbBgFrame.size = statusBarFrame.size; _statusBarBackgroundView.frame = sbBgFrame; [self.webView.superview addSubview:_statusBarBackgroundView];