From e5ef717aafe09462fcb3d65a69252773af1f1dee Mon Sep 17 00:00:00 2001 From: Nicholas Long Date: Thu, 8 Oct 2015 11:51:19 -0700 Subject: [PATCH] Added ability to alphaFade entire navbar instead of just it's subviews. Transfered userInteractionEnabled state from extensionView to extensionViewContainer. --- TLYShyNavBar/TLYShyNavBarManager.h | 1 + TLYShyNavBar/TLYShyNavBarManager.m | 3 +++ TLYShyNavBar/TLYShyViewController.h | 1 + TLYShyNavBar/TLYShyViewController.m | 12 ++++++++---- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 234361f..9f4421b 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -56,6 +56,7 @@ * Defaults to YES */ @property (nonatomic, getter = isAlphaFadeEnabled) BOOL alphaFadeEnabled; +@property (nonatomic, getter = isAlphaFadeEntireNavBarEnabled) BOOL alphaFadeEntireNavBar; @property (nonatomic) BOOL disable; diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 2286e88..d10f8a9 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -100,6 +100,7 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage self.contractionResistance = 0.f; self.alphaFadeEnabled = YES; + self.alphaFadeEntireNavBar = NO; self.previousScrollInsets = UIEdgeInsetsZero; self.previousYOffset = NAN; @@ -320,6 +321,7 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage // 6 - Update the shyViewController self.navBarController.alphaFadeEnabled = self.alphaFadeEnabled; + self.navBarController.alphaFadeEntireNavBar = self.alphaFadeEntireNavBar; [self.navBarController updateYOffset:deltaY]; } @@ -382,6 +384,7 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage self.extensionViewContainer.frame = bounds; [self.extensionViewContainer addSubview:view]; + self.extensionViewContainer.userInteractionEnabled = view.userInteractionEnabled; /* Disable scroll handling temporarily while laying out views to avoid double-changing content * offsets in _handleScrolling. */ diff --git a/TLYShyNavBar/TLYShyViewController.h b/TLYShyNavBar/TLYShyViewController.h index 1789bbc..9ca4e32 100644 --- a/TLYShyNavBar/TLYShyViewController.h +++ b/TLYShyNavBar/TLYShyViewController.h @@ -37,6 +37,7 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic) BOOL hidesAfterContraction; @property (nonatomic) BOOL alphaFadeEnabled; +@property (nonatomic) BOOL alphaFadeEntireNavBar; @property (nonatomic, readonly) CGFloat totalHeight; diff --git a/TLYShyNavBar/TLYShyViewController.m b/TLYShyNavBar/TLYShyViewController.m index 1e4194e..43307fc 100644 --- a/TLYShyNavBar/TLYShyViewController.m +++ b/TLYShyNavBar/TLYShyViewController.m @@ -61,8 +61,12 @@ const CGFloat contractionVelocity = 300.f; // This method is courtesy of GTScrollNavigationBar // https://github.com/luugiathuy/GTScrollNavigationBar -- (void)_updateSubviewsToAlpha:(CGFloat)alpha +- (void)_updateViewsToAlpha:(CGFloat)alpha { + if (_alphaFadeEntireNavBar) { + self.view.alpha = alpha; + } + for (UIView* view in self.view.subviews) { bool isBackgroundView = view == self.view.subviews[0]; @@ -83,7 +87,7 @@ const CGFloat contractionVelocity = 300.f; if (!alphaFadeEnabled) { - [self _updateSubviewsToAlpha:1.f]; + [self _updateViewsToAlpha:1.f]; } } @@ -113,7 +117,7 @@ const CGFloat contractionVelocity = 300.f; if (self.alphaFadeEnabled) { - [self _updateSubviewsToAlpha:newAlpha]; + [self _updateViewsToAlpha:newAlpha]; } } @@ -163,7 +167,7 @@ const CGFloat contractionVelocity = 300.f; if (self.hidesSubviews && self.alphaFadeEnabled) { - [self _updateSubviewsToAlpha:1.f]; + [self _updateViewsToAlpha:1.f]; } CGFloat amountToMove = self.expandedCenterValue.y - self.view.center.y;