From f071460d7adaa88e53edf9c303cf1dc9ea2475d6 Mon Sep 17 00:00:00 2001 From: Yoshi Sugawara Date: Sun, 23 Sep 2018 22:45:44 -1000 Subject: [PATCH] use safe area to account for notch for iPhone X and adjust main view size --- ui/drivers/cocoa/cocoa_common.m | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 8ce30fe99a..09163291c8 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -191,7 +191,7 @@ void *glkitview_init(void); { float width = 0.0f, height = 0.0f, tenpctw, tenpcth; RAScreen *screen = (__bridge RAScreen*)get_chosen_screen(); - UIInterfaceOrientation orientation = self.interfaceOrientation; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGRect screenSize = [screen bounds]; SEL selector = NSSelectorFromString(BOXSTRING("coordinateSpace")); @@ -212,8 +212,40 @@ void *glkitview_init(void); g_pause_indicator_view.frame = CGRectMake(tenpctw * 4.0f, 0.0f, tenpctw * 2.0f, tenpcth); [g_pause_indicator_view viewWithTag:1].frame = CGRectMake(0, 0, tenpctw * 2.0f, tenpcth); + + [self adjustViewFrameForSafeArea]; } +-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + if (@available(iOS 11, *)) { + [coordinator animateAlongsideTransition:^(id _Nonnull context) { + [self adjustViewFrameForSafeArea]; + } completion:^(id _Nonnull context) { + }]; + } +} + +-(void)adjustViewFrameForSafeArea { + // This is for adjusting the view frame to account for the notch in iPhone X phones + if (@available(iOS 11, *)) { + RAScreen *screen = (__bridge RAScreen*)get_chosen_screen(); + CGRect screenSize = [screen bounds]; + UIEdgeInsets inset = [[UIApplication sharedApplication] delegate].window.safeAreaInsets; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + CGRect newFrame = screenSize; + if ( orientation == UIInterfaceOrientationPortrait ) { + newFrame = CGRectMake(screenSize.origin.x, screenSize.origin.y + inset.top, screenSize.size.width, screenSize.size.height - inset.top); + } else if ( orientation == UIInterfaceOrientationLandscapeLeft ) { + newFrame = CGRectMake(screenSize.origin.x, screenSize.origin.y, screenSize.size.width - inset.right, screenSize.size.height); + } else if ( orientation == UIInterfaceOrientationLandscapeRight ) { + newFrame = CGRectMake(screenSize.origin.x + inset.left, screenSize.origin.y, screenSize.size.width - inset.left, screenSize.size.height); + } + self.view.frame = newFrame; + } +} + + #define ALMOST_INVISIBLE (.021f) - (void)hidePauseButton