From e32543c31b730d25a7280c331c8e74746aea57de Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sat, 8 Aug 2015 18:19:57 -0400 Subject: [PATCH 1/4] If the viewController is within a popover or other modal view, it should not be placed a status bar height below the top of that view. This fixes the use of shyNavBars in those settings. --- TLYShyNavBar/TLYShyNavBarManager.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 13fc944..68fcba0 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -20,12 +20,16 @@ // Thanks to SO user, MattDiPasquale // http://stackoverflow.com/questions/12991935/how-to-programmatically-get-ios-status-bar-height/16598350#16598350 -static inline CGFloat AACStatusBarHeight() +static inline CGFloat AACStatusBarHeight(UIViewController *viewController) { if ([UIApplication sharedApplication].statusBarHidden) { return 0.f; } + if (viewController.presentingViewController != nil) + { + return 0.f; + } CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size; return MIN(MIN(statusBarSize.width, statusBarSize.height), 20.0f); @@ -96,10 +100,12 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage self.navBarController = [[TLYShyViewController alloc] init]; self.navBarController.hidesSubviews = YES; + __weak __typeof(self) weakSelf = self; + self.navBarController.expandedCenter = ^(UIView *view) { return CGPointMake(CGRectGetMidX(view.bounds), - CGRectGetMidY(view.bounds) + AACStatusBarHeight()); + CGRectGetMidY(view.bounds) + AACStatusBarHeight(weakSelf.viewController)); }; self.navBarController.contractionAmount = ^(UIView *view) @@ -119,7 +125,6 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage return CGRectGetHeight(view.bounds); }; - __weak __typeof(self) weakSelf = self; self.extensionController.expandedCenter = ^(UIView *view) { return CGPointMake(CGRectGetMidX(view.bounds), @@ -290,7 +295,7 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage deltaY = MIN(0, availableResistance + deltaY); } - else if (self.scrollView.contentOffset.y > -AACStatusBarHeight()) + else if (self.scrollView.contentOffset.y > -AACStatusBarHeight(self.viewController)) { CGFloat availableResistance = self.expansionResistance - self.resistanceConsumed; self.resistanceConsumed = MIN(self.expansionResistance, self.resistanceConsumed + deltaY); From ade5b370bd485c338603eeded34b2d8c22f6b587 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 9 Aug 2015 18:48:43 -0400 Subject: [PATCH 2/4] When avoiding the status bar, check the view's position relative to the status bar rather than assuming that the presence of a presentingViewController is sufficient; otherwise we would not avoid the status bar in full screen modal views. --- TLYShyNavBar/TLYShyNavBarManager.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 68fcba0..ba38c48 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -26,8 +26,12 @@ static inline CGFloat AACStatusBarHeight(UIViewController *viewController) { return 0.f; } - if (viewController.presentingViewController != nil) - { + + // Modal views do not overlap the status bar, so no allowance need be made for it + UIView *view = viewController.view; + CGRect frame = [view.superview convertRect:view.frame toView:view.window]; + BOOL viewOverlapsStatusBar = frame.origin.y < 20.f; + if (!viewOverlapsStatusBar) { return 0.f; } From 5f6e0a07f43d1b00915f0aa5644966b6594c6348 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 16 Aug 2015 18:44:20 -0400 Subject: [PATCH 3/4] Fix determining the size of the status bar when it is more than 20 pixels, which happens for example if a call or GPS are active. --- TLYShyNavBar/TLYShyNavBarManager.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index ba38c48..959ffbf 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -28,15 +28,17 @@ static inline CGFloat AACStatusBarHeight(UIViewController *viewController) } // Modal views do not overlap the status bar, so no allowance need be made for it + CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size; + CGFloat statusBarHeight = MIN(statusBarSize.width, statusBarSize.height); + UIView *view = viewController.view; CGRect frame = [view.superview convertRect:view.frame toView:view.window]; - BOOL viewOverlapsStatusBar = frame.origin.y < 20.f; + BOOL viewOverlapsStatusBar = frame.origin.y < statusBarHeight; if (!viewOverlapsStatusBar) { return 0.f; } - CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size; - return MIN(MIN(statusBarSize.width, statusBarSize.height), 20.0f); + return statusBarHeight; } static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManagerKVOContext; From 33c65bd32108d615a7b0cad4aad496514404dcd5 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 16 Aug 2015 18:45:01 -0400 Subject: [PATCH 4/4] Fix positioning of the navigation bar when the status bar is larger than 20 pixels --- TLYShyNavBar/TLYShyNavBarManager.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 959ffbf..87a48b8 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -110,8 +110,16 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage self.navBarController.expandedCenter = ^(UIView *view) { + CGFloat statusBarHeight = AACStatusBarHeight(weakSelf.viewController); + /* The standard status bar is 20 pixels. The navigation bar extends 20 pixels up so it is overlapped by the status bar. + * When there is a larger than 20 pixel status bar (e.g. a phone call is in progress or GPS is active), the center needs + * to shift up 20 pixels to avoid this 'dead space' being visible above the usual nav bar. + */ + if (statusBarHeight > 20) + statusBarHeight -= 20; + return CGPointMake(CGRectGetMidX(view.bounds), - CGRectGetMidY(view.bounds) + AACStatusBarHeight(weakSelf.viewController)); + CGRectGetMidY(view.bounds) + statusBarHeight); }; self.navBarController.contractionAmount = ^(UIView *view)