Merge pull request #81 from evands/fix-shynav-in-popover_isolated
Fix shy nav bar positioning when shown in a popover or modal dialog
This commit is contained in:
commit
fed648bcc3
|
|
@ -20,15 +20,25 @@
|
|||
// 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;
|
||||
}
|
||||
|
||||
CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
|
||||
return MIN(MIN(statusBarSize.width, statusBarSize.height), 20.0f);
|
||||
// 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 < statusBarHeight;
|
||||
if (!viewOverlapsStatusBar) {
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
return statusBarHeight;
|
||||
}
|
||||
|
||||
static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManagerKVOContext;
|
||||
|
|
@ -96,10 +106,20 @@ 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)
|
||||
{
|
||||
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());
|
||||
CGRectGetMidY(view.bounds) + statusBarHeight);
|
||||
};
|
||||
|
||||
self.navBarController.contractionAmount = ^(UIView *view)
|
||||
|
|
@ -119,7 +139,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 +309,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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue