From 2f8a8a52f2c0bf1957b9dd7f00ec417f5da9ddd7 Mon Sep 17 00:00:00 2001 From: James Sharp Date: Thu, 18 Feb 2016 19:42:29 +0000 Subject: [PATCH] Fix split screen issues in iOS 9 --- src/ios/CDVStatusBar.m | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index 4077e369..77cb9cb0 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -99,6 +99,10 @@ -(void)statusBarDidChangeFrame:(NSNotification*)notification }); } +-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { + [self resizeWebView]; +} + - (void)pluginInitialize { BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0")); @@ -201,13 +205,17 @@ - (void) initializeStatusBarBackgroundView - (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 (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && (rect.size.width < rect.size.height)) { - CGFloat temp = rect.size.width; - rect.size.width = rect.size.height; - rect.size.height = temp; - rect.origin = CGPointZero; + BOOL isIOS8 = (IsAtLeastiOSVersion(@"8.0")); + + if (!isIOS8) { + if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && (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; } @@ -217,7 +225,7 @@ - (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView if (!IsAtLeastiOSVersion(@"7.0") || statusBarOverlaysWebView == _statusBarOverlaysWebView) { return; } - + _statusBarOverlaysWebView = statusBarOverlaysWebView; [self resizeWebView]; @@ -376,7 +384,7 @@ - (void) hide:(CDVInvokedUrlCommand*)command if (!app.isStatusBarHidden) { - + [self hideStatusBar]; if (IsAtLeastiOSVersion(@"7.0")) { @@ -441,28 +449,27 @@ - (void) show:(CDVInvokedUrlCommand*)command } -(void)resizeWebView { - - CGRect bounds = [[UIScreen mainScreen] bounds]; - + CGRect bounds = self.viewController.view.window.frame; + bounds = [self invertFrameIfNeeded:bounds orientation:self.viewController.interfaceOrientation]; - + if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { self.viewController.view.frame = bounds; } - + self.webView.frame = bounds; - + if (!self.statusBarOverlaysWebView) { - + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation]; - + CGRect frame = self.webView.frame; frame.origin.y = statusBarFrame.size.height; frame.size.height -= statusBarFrame.size.height; self.webView.frame = frame; } - + } - (void) dealloc