From ca9614e337152528dc948be950c98705df1f7ab5 Mon Sep 17 00:00:00 2001 From: How Else Date: Tue, 5 Dec 2017 19:05:50 +0200 Subject: [PATCH] Fix for navigation bar when animating UINavigationController as contentViewController in iOS 11 --- RESideMenu/RESideMenu.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/RESideMenu/RESideMenu.m b/RESideMenu/RESideMenu.m index b6b8efd9..a3ff2923 100644 --- a/RESideMenu/RESideMenu.m +++ b/RESideMenu/RESideMenu.m @@ -285,6 +285,7 @@ - (void)showLeftMenuViewController [UIView animateWithDuration:self.animationDuration animations:^{ if (self.scaleContentView) { self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue); + [self updateContentViewAdditionalSafeAreaInsets]; } else { self.contentViewContainer.transform = CGAffineTransformIdentity; } @@ -333,6 +334,7 @@ - (void)showRightMenuViewController [UIView animateWithDuration:self.animationDuration animations:^{ if (self.scaleContentView) { self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue); + [self updateContentViewAdditionalSafeAreaInsets]; } else { self.contentViewContainer.transform = CGAffineTransformIdentity; } @@ -388,6 +390,7 @@ - (void)hideMenuViewControllerAnimated:(BOOL)animated } strongSelf.contentViewContainer.transform = CGAffineTransformIdentity; strongSelf.contentViewContainer.frame = strongSelf.view.bounds; + [self updateContentViewAdditionalSafeAreaInsets]; if (strongSelf.scaleMenuView) { strongSelf.menuViewContainer.transform = strongSelf.menuViewControllerTransformation; } @@ -474,6 +477,21 @@ - (void)resetContentViewScale self.contentViewContainer.frame = frame; } +- (void)updateContentViewAdditionalSafeAreaInsets +{ + if (@available(iOS 11.0, *)) { + UIEdgeInsets insets = self.contentViewController.additionalSafeAreaInsets; + insets.top = CGRectGetMinY(self.contentViewContainer.frame); + CGFloat topSafeArea = CGRectGetMinY(self.view.safeAreaLayoutGuide.layoutFrame); + if (insets.top > topSafeArea) { + insets.top = topSafeArea; + } else if (insets.top < 0.0) { + insets.top = 0.0; + } + self.contentViewController.additionalSafeAreaInsets = insets; + } +} + #pragma mark - #pragma mark iOS 7 Motion Effects (Private) @@ -649,9 +667,11 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer CGFloat oppositeScale = (1 - (contentViewScale - 1)); self.contentViewContainer.transform = CGAffineTransformMakeScale(oppositeScale, oppositeScale); self.contentViewContainer.transform = CGAffineTransformTranslate(self.contentViewContainer.transform, point.x, 0); + [self updateContentViewAdditionalSafeAreaInsets]; } else { self.contentViewContainer.transform = CGAffineTransformMakeScale(contentViewScale, contentViewScale); self.contentViewContainer.transform = CGAffineTransformTranslate(self.contentViewContainer.transform, point.x, 0); + [self updateContentViewAdditionalSafeAreaInsets]; } self.leftMenuViewController.view.hidden = self.contentViewContainer.frame.origin.x < 0; @@ -660,11 +680,13 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer if (!self.leftMenuViewController && self.contentViewContainer.frame.origin.x > 0) { self.contentViewContainer.transform = CGAffineTransformIdentity; self.contentViewContainer.frame = self.view.bounds; + [self updateContentViewAdditionalSafeAreaInsets]; self.visible = NO; self.leftMenuVisible = NO; } else if (!self.rightMenuViewController && self.contentViewContainer.frame.origin.x < 0) { self.contentViewContainer.transform = CGAffineTransformIdentity; self.contentViewContainer.frame = self.view.bounds; + [self updateContentViewAdditionalSafeAreaInsets]; self.visible = NO; self.rightMenuVisible = NO; } @@ -791,6 +813,7 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte if (self.scaleContentView) { self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue); + [self updateContentViewAdditionalSafeAreaInsets]; } else { self.contentViewContainer.transform = CGAffineTransformIdentity; }