From b4e5d88fa2c829bbb5fbc5d303a45530812e0cc1 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 13:55:22 -0400 Subject: [PATCH 01/24] scale behaviour --- .../ShyControllers/TLYShyViewController.h | 1 + .../ShyControllers/TLYShyViewController.m | 43 +++++++++++++++++-- TLYShyNavBar/TLYShyNavBarManager.h | 5 +++ TLYShyNavBar/TLYShyNavBarManager.m | 6 +-- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.h b/TLYShyNavBar/ShyControllers/TLYShyViewController.h index 2c6a2fb..ce296b6 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.h @@ -38,6 +38,7 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic, weak) UIView *view; @property (nonatomic) TLYShyNavBarFade fadeBehavior; +@property (nonatomic) BOOL scaleBehaviour; /* Sticky means it will always stay in expanded state */ diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index 19a6b62..633845f 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -76,6 +76,12 @@ - (BOOL)expanded #pragma mark - Private methods +- (void)_onProgressUpdate:(CGFloat)progress +{ + [self _onAlphaUpdate:progress]; + [self _onScaleUpdate:progress]; +} + - (void)_onAlphaUpdate:(CGFloat)alpha { if (self.sticky) @@ -120,6 +126,26 @@ - (void)_updateSubviewsAlpha:(CGFloat)alpha } } +- (void)_onScaleUpdate:(CGFloat)scale +{ + if (self.sticky) { + [self _updateSubviewsScale:1.f]; + return; + } + + [self _updateSubviewsScale:self.scaleBehaviour ? scale : 1.f]; +} + +- (void)_updateSubviewsScale:(CGFloat)scale +{ + if ([self.view isKindOfClass:[UINavigationBar class]]) { + UINavigationBar *navigationBar = (UINavigationBar *)self.view; + for (UIView* view in navigationBar.topItem.titleView.subviews) { + view.transform = scale < 1 ? CGAffineTransformMakeScale(scale, scale) : CGAffineTransformIdentity; + } + } +} + - (void)_updateCenter:(CGPoint)newCenter { CGPoint currentCenter = self.view.center; @@ -141,6 +167,15 @@ - (void)setFadeBehavior:(TLYShyNavBarFade)fadeBehavior } } +- (void)setScaleBehaviour:(BOOL)scaleBehaviour +{ + _scaleBehaviour = scaleBehaviour; + + if (!scaleBehaviour) { + [self _onScaleUpdate:1.f]; + } +} + - (void)offsetCenterBy:(CGPoint)deltaPoint { self.view.center = CGPointMake(self.view.center.x + deltaPoint.x, @@ -167,8 +202,8 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / self.contractionAmountValue; newAlpha = MIN(MAX(FLT_EPSILON, newAlpha), 1.f); - - [self _onAlphaUpdate:newAlpha]; + + [self _onProgressUpdate:newAlpha]; residual = newYOffset - newYCenter; @@ -231,7 +266,7 @@ - (CGFloat)expand { self.view.hidden = NO; - [self _onAlphaUpdate:1.f]; + [self _onProgressUpdate:1.f]; CGFloat amountToMove = self.expandedCenterValue.y - self.view.center.y; @@ -245,7 +280,7 @@ - (CGFloat)contract { CGFloat amountToMove = self.contractedCenterValue.y - self.view.center.y; - [self _onAlphaUpdate:FLT_EPSILON]; + [self _onProgressUpdate:FLT_EPSILON]; [self _updateCenter:self.contractedCenterValue]; [self.subShyController contract]; diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 0e507dc..6120f6f 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -67,6 +67,11 @@ */ @property (nonatomic) TLYShyNavBarFade fadeBehavior; +/* Choose if the navbar's subviews scale as the navbar contracts/expands. + * Defaults to NO + */ +@property (nonatomic) BOOL scaleBehavior; + /* Use this to set if the controller have any kind of custom refresh control */ @property (nonatomic) BOOL hasCustomRefreshControl; diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index d38ea8d..7d06d1f 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -60,11 +60,10 @@ - (instancetype)init /* Initialize defaults */ self.contracting = NO; self.previousContractionState = YES; - + self.scaleBehavior = YES; + self.fadeBehavior = TLYShyNavBarFadeSubviews; self.expansionResistance = 200.f; self.contractionResistance = 0.f; - - self.fadeBehavior = TLYShyNavBarFadeSubviews; self.previousYOffset = NAN; /* Initialize shy controllers */ @@ -310,6 +309,7 @@ - (void)_handleScrolling // 6 - Update the navigation bar shyViewController self.navBarController.fadeBehavior = self.fadeBehavior; + self.navBarController.scaleBehaviour = self.scaleBehavior; // 7 - Inform the delegate if needed CGFloat maxNavY = CGRectGetMaxY(self.navBarController.view.frame); From 509a09a2eabcdfdb277ae1c7c5697ccf576a9985 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 13:56:24 -0400 Subject: [PATCH 02/24] typos --- TLYShyNavBar/TLYShyNavBarManager.h | 2 +- TLYShyNavBar/TLYShyNavBarManager.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 6120f6f..984914f 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -46,7 +46,7 @@ @property (nonatomic, readonly) CGRect extensionViewBounds; /* Make the navigation bar stick to the top without collapsing - * Deatuls to NO + * Defaults to NO */ @property (nonatomic) BOOL stickyNavigationBar; diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 7d06d1f..dac47a3 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -79,7 +79,7 @@ - (instancetype)init self.extensionController.view = self.extensionViewContainer; /* hierarchy setup */ - /* StatusBar <-- navbar <-->> extension <--> scrollView + /* StatusBar <--> navBar <--> extensionView <--> scrollView */ self.navBarController.parent = self.statusBarController; self.navBarController.child = self.extensionController; From d02e23d3d6323de3f7a63feee3fa708c3199806b Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 13:58:14 -0400 Subject: [PATCH 03/24] removed KVO --- TLYShyNavBar/TLYShyNavBarManager.m | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index dac47a3..7dbac21 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -20,9 +20,6 @@ #import -static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManagerKVOContext; - - #pragma mark - TLYShyNavBarManager class @interface TLYShyNavBarManager () @@ -111,7 +108,6 @@ - (void)dealloc } [[NSNotificationCenter defaultCenter] removeObserver:self]; - [_scrollView removeObserver:self forKeyPath:@"contentSize" context:kTLYShyNavBarManagerKVOContext]; } #pragma mark - Properties @@ -141,8 +137,6 @@ - (void)setViewController:(UIViewController *)viewController - (void)setScrollView:(UIScrollView *)scrollView { - [_scrollView removeObserver:self forKeyPath:@"contentSize" context:kTLYShyNavBarManagerKVOContext]; - if (_scrollView.delegate == self.delegateProxy) { _scrollView.delegate = self.delegateProxy.originalDelegate; @@ -167,8 +161,6 @@ - (void)setScrollView:(UIScrollView *)scrollView [self cleanup]; [self layoutViews]; - - [_scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:kTLYShyNavBarManagerKVOContext]; } - (CGRect)extensionViewBounds @@ -360,26 +352,6 @@ - (void)_handleScrollingEnded [self.navBarController snap:self.contracting completion:completion]; } -#pragma mark - KVO - -- (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(id)object - change:(NSDictionary *)change - context:(void *)context -{ - if (context == kTLYShyNavBarManagerKVOContext) - { - if (self.isViewControllerVisible && ![self _scrollViewIsSuffecientlyLong]) - { - [self.navBarController expand]; - } - } - else - { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } -} - #pragma mark - public methods - (void)setExtensionView:(UIView *)view From 6e31e63af7c1e52b24b9ec85be1b13efeb2e5bb9 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 13:59:11 -0400 Subject: [PATCH 04/24] fixed delegate --- TLYShyNavBar/TLYShyNavBarManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 7dbac21..e4f5a30 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -331,7 +331,7 @@ - (void)_handleScrollingEnded return; } - __weak __typeof(self) weakSelf; + __weak __typeof(self) weakSelf = self; void (^completion)() = ^ { __typeof(self) strongSelf = weakSelf; From b66f91b898e9708eecbad577c07f32242ff4e0cd Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:04:22 -0400 Subject: [PATCH 05/24] TLYShyViewControllerDelegate --- TLYShyNavBar/ShyControllers/TLYShyViewController.h | 14 ++++++++++++++ TLYShyNavBar/ShyControllers/TLYShyViewController.m | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.h b/TLYShyNavBar/ShyControllers/TLYShyViewController.h index ce296b6..6cc8d56 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.h @@ -19,6 +19,8 @@ typedef CGPoint(^TLYShyViewControllerExpandedCenterBlock)(UIView *view); typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); +@protocol TLYShyViewControllerDelegate; + /* CLASS DESCRIPTION: * ================== * A shy view is a view that contracts when a scrolling event is @@ -44,6 +46,8 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); */ @property (nonatomic) BOOL sticky; +@property (nonatomic, weak) id delegate; + - (void)offsetCenterBy:(CGPoint)deltaPoint; - (CGFloat)updateYOffset:(CGFloat)deltaY; @@ -56,5 +60,15 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @end +@protocol TLYShyViewControllerDelegate + +@optional + +- (void)shyViewControllerDidContract:(TLYShyViewController *) shyViewController; +- (void)shyViewControllerDidExpand:(TLYShyViewController *) shyViewController; + +@end + + @interface TLYShyViewController (AsParent) @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index 633845f..f7760b4 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -273,6 +273,8 @@ - (CGFloat)expand [self _updateCenter:self.expandedCenterValue]; [self.subShyController expand]; + [self.delegate shyViewControllerDidExpand:self]; + return amountToMove; } @@ -285,6 +287,8 @@ - (CGFloat)contract [self _updateCenter:self.contractedCenterValue]; [self.subShyController contract]; + [self.delegate shyViewControllerDidContract:self]; + return amountToMove; } From 4828101cfc647a305c42d14e25ad065d7cc8c077 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:06:34 -0400 Subject: [PATCH 06/24] cleanup --- TLYShyNavBar/TLYShyNavBarManager.m | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index e4f5a30..a5b88a4 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -24,7 +24,7 @@ @interface TLYShyNavBarManager () -@property (nonatomic, strong) id statusBarController; +@property (nonatomic, strong) TLYShyStatusBarController *statusBarController; @property (nonatomic, strong) TLYShyViewController *navBarController; @property (nonatomic, strong) TLYShyViewController *extensionController; @property (nonatomic, strong) TLYShyScrollViewController *scrollViewController; @@ -66,6 +66,7 @@ - (instancetype)init /* Initialize shy controllers */ self.statusBarController = [[TLYShyStatusBarController alloc] init]; self.scrollViewController = [[TLYShyScrollViewController alloc] init]; + self.navBarController = [[TLYShyViewController alloc] init]; self.extensionViewContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100.f, 0.f)]; @@ -360,13 +361,10 @@ - (void)setExtensionView:(UIView *)view { [_extensionView removeFromSuperview]; _extensionView = view; + + view.frame = view.bounds; - CGRect bounds = view.frame; - bounds.origin = CGPointZero; - - view.frame = bounds; - - self.extensionViewContainer.frame = bounds; + self.extensionViewContainer.frame = view.bounds; [self.extensionViewContainer addSubview:view]; self.extensionViewContainer.userInteractionEnabled = view.userInteractionEnabled; @@ -379,9 +377,10 @@ - (void)setExtensionView:(UIView *)view } } -- (void)prepareForDisplay +- (void)cleanup { - [self cleanup]; + [self.navBarController expand]; + self.previousYOffset = NAN; } - (void)layoutViews @@ -393,10 +392,6 @@ - (void)layoutViews } } -- (void)cleanup -{ - [self.navBarController expand]; - self.previousYOffset = NAN; } #pragma mark - UIScrollViewDelegate methods @@ -463,7 +458,7 @@ + (void)load - (void)tly_swizzledViewWillAppear:(BOOL)animated { - [[self _internalShyNavBarManager] prepareForDisplay]; + [[self _internalShyNavBarManager] cleanup]; [self tly_swizzledViewWillAppear:animated]; } From 1fcc965f1c9c4eccf24fc76cda5f7157bd069fb6 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:08:21 -0400 Subject: [PATCH 07/24] calculateTotalHeightRecursively & calculateBottomRecursively --- TLYShyNavBar/ShyControllers/TLYShyParent.h | 1 + TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m | 5 +++++ TLYShyNavBar/ShyControllers/TLYShyViewController.m | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyParent.h b/TLYShyNavBar/ShyControllers/TLYShyParent.h index d54fad6..a4a983c 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyParent.h +++ b/TLYShyNavBar/ShyControllers/TLYShyParent.h @@ -19,6 +19,7 @@ - (CGFloat)maxYRelativeToView:(UIView *)superview; - (CGFloat)calculateTotalHeightRecursively; +- (CGFloat)calculateBottomRecursively; @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m index 4e9252c..d11bf7d 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m @@ -64,5 +64,10 @@ - (CGFloat)calculateTotalHeightRecursively return [self _statusBarHeight]; } +- (CGFloat)calculateBottomRecursively +{ + return [self _statusBarHeight]; +} + @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index f7760b4..75c6481 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -21,7 +21,12 @@ - (CGFloat)maxYRelativeToView:(UIView *)superview - (CGFloat)calculateTotalHeightRecursively { - return CGRectGetHeight(self.view.bounds) + [self.parent calculateTotalHeightRecursively]; + return (self.expanded ? CGRectGetHeight(self.view.bounds) : 0) + [self.parent calculateTotalHeightRecursively]; +} + +- (CGFloat)calculateBottomRecursively +{ + return (self.sticky || self.expanded) && self.view.subviews.count > 0 ? self.view.frame.origin.y + self.view.frame.size.height : [self.parent calculateBottomRecursively]; } @end From f6d37c8cef6101d028f03b713092630947a90012 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:08:56 -0400 Subject: [PATCH 08/24] readonly contracted & expanded --- TLYShyNavBar/ShyControllers/TLYShyViewController.h | 3 +++ TLYShyNavBar/ShyControllers/TLYShyViewController.m | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.h b/TLYShyNavBar/ShyControllers/TLYShyViewController.h index 6cc8d56..aef9087 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.h @@ -42,6 +42,9 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic) TLYShyNavBarFade fadeBehavior; @property (nonatomic) BOOL scaleBehaviour; +@property (nonatomic, readonly) BOOL contracted; +@property (nonatomic, readonly) BOOL expanded; + /* Sticky means it will always stay in expanded state */ @property (nonatomic) BOOL sticky; diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index 75c6481..2e0d407 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -39,9 +39,6 @@ @interface TLYShyViewController () @property (nonatomic, assign) CGPoint contractedCenterValue; -@property (nonatomic, assign) BOOL contracted; -@property (nonatomic, assign) BOOL expanded; - @end @implementation TLYShyViewController From 61626b695cf2fb42caf28834899be1967cf65bca Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:12:09 -0400 Subject: [PATCH 09/24] finish animation before overlapping status bar --- TLYShyNavBar/ShyControllers/TLYShyViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index 2e0d407..b814c2d 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -202,7 +202,7 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY [self _updateCenter:CGPointMake(self.expandedCenterValue.x, newYCenter)]; - CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / self.contractionAmountValue; + CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / (self.contractionAmountValue - [UIApplication sharedApplication].statusBarFrame.size.height); newAlpha = MIN(MAX(FLT_EPSILON, newAlpha), 1.f); [self _onProgressUpdate:newAlpha]; From 28ed3c83de850379aa710c6fe4ff80bfba18be0e Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:12:58 -0400 Subject: [PATCH 10/24] height --- TLYShyNavBar/TLYShyNavBarManager.h | 4 ++++ TLYShyNavBar/TLYShyNavBarManager.m | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 984914f..f87f26d 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -62,6 +62,10 @@ @property (nonatomic) CGFloat expansionResistance; // default 200 @property (nonatomic) CGFloat contractionResistance; // default 0 +/* The combined height of all the nav bar including the extension view and status bar + */ +@property (nonatomic, readonly) CGFloat height; + /* Choose how the navbar fades as it contracts/expands. * Defaults to FadeSubviews */ diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index a5b88a4..5315e3e 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -220,6 +220,11 @@ - (void)setStickyExtensionView:(BOOL)stickyExtensionView self.extensionController.sticky = stickyExtensionView; } +- (CGFloat)height +{ + return self.extensionController.calculateTotalHeightRecursively; +} + #pragma mark - Private methods From a3e182fd13e9c8a96e5341401f292d7c5723599d Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:13:21 -0400 Subject: [PATCH 11/24] readonly contracting --- TLYShyNavBar/TLYShyNavBarManager.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index f87f26d..3b1ef79 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -66,6 +66,10 @@ */ @property (nonatomic, readonly) CGFloat height; +/* Check the state of the control + */ +@property (nonatomic, readonly) BOOL contracting; + /* Choose how the navbar fades as it contracts/expands. * Defaults to FadeSubviews */ From 7cb790089b9d0cd472405386067bee2fdf5633af Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:14:29 -0400 Subject: [PATCH 12/24] removed viewWillLayoutSubviews swizzle --- TLYShyNavBar/TLYShyNavBarManager.m | 7 ------- 1 file changed, 7 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 5315e3e..dd8bbe1 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -454,7 +454,6 @@ + (void)load static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ [self tly_swizzleInstanceMethod:@selector(viewWillAppear:) withReplacement:@selector(tly_swizzledViewWillAppear:)]; - [self tly_swizzleInstanceMethod:@selector(viewWillLayoutSubviews) withReplacement:@selector(tly_swizzledViewDidLayoutSubviews)]; [self tly_swizzleInstanceMethod:@selector(viewWillDisappear:) withReplacement:@selector(tly_swizzledViewWillDisappear:)]; }); } @@ -467,12 +466,6 @@ - (void)tly_swizzledViewWillAppear:(BOOL)animated [self tly_swizzledViewWillAppear:animated]; } -- (void)tly_swizzledViewDidLayoutSubviews -{ - [[self _internalShyNavBarManager] layoutViews]; - [self tly_swizzledViewDidLayoutSubviews]; -} - - (void)tly_swizzledViewWillDisappear:(BOOL)animated { [[self _internalShyNavBarManager] cleanup]; From db5a1805677737906a53e7d8192b114df4ad6e9e Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:15:12 -0400 Subject: [PATCH 13/24] removed applicationDidChangeStatusBarFrame --- TLYShyNavBar/TLYShyNavBarManager.m | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index dd8bbe1..d1edcd2 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -91,11 +91,6 @@ - (instancetype)init selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(applicationDidChangeStatusBarFrame:) - name:UIApplicationDidChangeStatusBarFrameNotification - object:nil]; } return self; } @@ -434,11 +429,6 @@ - (void)applicationDidBecomeActive:(NSNotification *)notification } } -- (void)applicationDidChangeStatusBarFrame:(NSNotification *)notification -{ - [self.navBarController expand]; -} - @end #pragma mark - UIViewController+TLYShyNavBar category From adaf221f05465701a6d58b753766172afb943e38 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:16:36 -0400 Subject: [PATCH 14/24] bottom --- TLYShyNavBar/TLYShyNavBarManager.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index d1edcd2..c4b6d20 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -36,6 +36,7 @@ @interface TLYShyNavBarManager () @property (nonatomic, assign) CGFloat previousYOffset; @property (nonatomic, assign) CGFloat resistanceConsumed; +@property (nonatomic, readonly) CGFloat bottom; @property (nonatomic, assign) BOOL contracting; @property (nonatomic, assign) BOOL previousContractionState; @@ -220,6 +221,11 @@ - (CGFloat)height return self.extensionController.calculateTotalHeightRecursively; } +- (CGFloat)bottom +{ + return self.extensionController.calculateBottomRecursively; +} + #pragma mark - Private methods From e804c463fc99c6f005bcb86cc022a86a47200ed2 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:17:08 -0400 Subject: [PATCH 15/24] isMidTransition --- TLYShyNavBar/TLYShyNavBarManager.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index c4b6d20..a614c05 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -41,6 +41,7 @@ @interface TLYShyNavBarManager () @property (nonatomic, assign) BOOL previousContractionState; @property (nonatomic, readonly) BOOL isViewControllerVisible; +@property (nonatomic, readonly) BOOL isMidTransition; @end @@ -170,6 +171,11 @@ - (BOOL)isViewControllerVisible return self.viewController.isViewLoaded && self.viewController.view.window; } +- (BOOL)isMidTransition +{ + return (!self.navBarController.expanded && !self.navBarController.contracted) || (!self.extensionController.expanded && !self.extensionController.contracted); +} + - (void)setDisable:(BOOL)disable { if (disable == _disable) From 640c27b70cc627a084a049652d65a9139b70597e Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:19:07 -0400 Subject: [PATCH 16/24] scrolling --- TLYShyNavBar/TLYShyNavBarManager.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index a614c05..a553ef8 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -37,6 +37,7 @@ @interface TLYShyNavBarManager () @property (nonatomic, assign) CGFloat resistanceConsumed; @property (nonatomic, readonly) CGFloat bottom; +@property (nonatomic, assign) BOOL scrolling; @property (nonatomic, assign) BOOL contracting; @property (nonatomic, assign) BOOL previousContractionState; @@ -57,6 +58,7 @@ - (instancetype)init self.delegateProxy = [[TLYDelegateProxy alloc] initWithMiddleMan:self]; /* Initialize defaults */ + self.scrolling = NO; self.contracting = NO; self.previousContractionState = YES; self.scaleBehavior = YES; @@ -254,6 +256,8 @@ - (BOOL)_shouldHandleScrolling - (void)_handleScrolling { + self.scrolling = YES; + if (![self _shouldHandleScrolling]) { return; @@ -339,6 +343,8 @@ - (void)_handleScrolling - (void)_handleScrollingEnded { + self.scrolling = NO; + if (!self.isViewControllerVisible) { return; From e5afba4749e57a04224d4c8e846bcd03a9a45dd2 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:20:24 -0400 Subject: [PATCH 17/24] removed layoutViews --- TLYShyNavBar/TLYShyNavBarManager.m | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index a553ef8..e8fafce 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -131,8 +131,6 @@ - (void)setViewController:(UIViewController *)viewController [self.viewController.view addSubview:self.extensionViewContainer]; self.navBarController.view = navbar; - - [self layoutViews]; } - (void)setScrollView:(UIScrollView *)scrollView @@ -160,7 +158,6 @@ - (void)setScrollView:(UIScrollView *)scrollView } [self cleanup]; - [self layoutViews]; } - (CGRect)extensionViewBounds @@ -390,7 +387,6 @@ - (void)setExtensionView:(UIView *)view * offsets in _handleScrolling. */ BOOL wasDisabled = self.disable; self.disable = YES; - [self layoutViews]; self.disable = wasDisabled; } } @@ -401,14 +397,8 @@ - (void)cleanup self.previousYOffset = NAN; } -- (void)layoutViews { - if (fabs([self.scrollViewController updateLayoutIfNeeded]) > FLT_EPSILON) { - [self.navBarController expand]; - [self.extensionViewContainer.superview bringSubviewToFront:self.extensionViewContainer]; - } -} } From f0e0751a277248ae741049184cbb8cfc15f2697e Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:22:59 -0400 Subject: [PATCH 18/24] automaticallyAdjustsScrollViewInsets --- TLYShyNavBar/TLYShyNavBarManager.h | 5 +++ TLYShyNavBar/TLYShyNavBarManager.m | 50 +++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 3b1ef79..31b2c35 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -84,6 +84,11 @@ */ @property (nonatomic) BOOL hasCustomRefreshControl; +/* Set this to true if you want this control to automatically adjust the scroll view insets + * Defaults to NO + */ +@property (nonatomic) BOOL automaticallyAdjustsScrollViewInsets; + /* Set NO to disable shyNavBar behavior temporarily. * Defaults to NO */ diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index e8fafce..e430a35 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -22,7 +22,7 @@ #pragma mark - TLYShyNavBarManager class -@interface TLYShyNavBarManager () +@interface TLYShyNavBarManager () @property (nonatomic, strong) TLYShyStatusBarController *statusBarController; @property (nonatomic, strong) TLYShyViewController *navBarController; @@ -72,6 +72,7 @@ - (instancetype)init self.scrollViewController = [[TLYShyScrollViewController alloc] init]; self.navBarController = [[TLYShyViewController alloc] init]; + self.navBarController.delegate = self; self.extensionViewContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100.f, 0.f)]; self.extensionViewContainer.backgroundColor = [UIColor clearColor]; @@ -79,6 +80,7 @@ - (instancetype)init self.extensionController = [[TLYShyViewController alloc] init]; self.extensionController.view = self.extensionViewContainer; + self.extensionController.delegate = self; /* hierarchy setup */ /* StatusBar <--> navBar <--> extensionView <--> scrollView @@ -156,8 +158,8 @@ - (void)setScrollView:(UIScrollView *)scrollView self.delegateProxy.originalDelegate = _scrollView.delegate; _scrollView.delegate = (id)self.delegateProxy; } - - [self cleanup]; + + [self updateScrollViewInsets]; } - (CGRect)extensionViewBounds @@ -334,8 +336,8 @@ - (void)_handleScrolling [self.navBarController updateYOffset:deltaY]; } - - self.previousYOffset = self.scrollView.contentOffset.y; + + [self updateScrollViewInsets]; } - (void)_handleScrollingEnded @@ -388,6 +390,8 @@ - (void)setExtensionView:(UIView *)view BOOL wasDisabled = self.disable; self.disable = YES; self.disable = wasDisabled; + + [self.extensionController expand]; } } @@ -397,9 +401,33 @@ - (void)cleanup self.previousYOffset = NAN; } +- (void)updateScrollViewInsets { + if (self.automaticallyAdjustsScrollViewInsets) { + id delegate = self.scrollView.delegate; + + self.scrollView.delegate = nil; + + self.scrollView.contentInset = UIEdgeInsetsMake(self.bottom, + self.scrollView.contentInset.left, + self.scrollView.contentInset.bottom, + self.scrollView.contentInset.right); + self.scrollView.scrollIndicatorInsets = self.scrollView.contentInset; + + if ((self.scrollView.contentOffset.y == 0 || + self.scrollView.contentOffset.y == -self.navBarController.calculateTotalHeightRecursively || + self.scrollView.contentOffset.y == -self.extensionController.calculateTotalHeightRecursively) + && !self.scrolling) + { + self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, -self.scrollView.contentInset.top); + } + + self.scrollView.delegate = delegate; + } + + self.previousYOffset = self.scrollView.contentOffset.y; } #pragma mark - UIScrollViewDelegate methods @@ -428,6 +456,18 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView [self _handleScrollingEnded]; } +#pragma mark - TLYShyViewControllerDelegate methods + +- (void)shyViewControllerDidExpand:(TLYShyViewController *)shyViewController +{ + [self updateScrollViewInsets]; +} + +- (void)shyViewControllerDidContract:(TLYShyViewController *)shyViewController +{ + [self updateScrollViewInsets]; +} + #pragma mark - NSNotificationCenter methods - (void)applicationDidBecomeActive:(NSNotification *)notification From 0701fa750769cc17893168e82895cc10666b0bca Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Thu, 4 Aug 2016 14:23:19 -0400 Subject: [PATCH 19/24] more delegate methods --- TLYShyNavBar/TLYShyNavBarManager.h | 6 ++- TLYShyNavBar/TLYShyNavBarManager.m | 81 +++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index 31b2c35..da34601 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -109,9 +109,13 @@ @optional -- (void)shyNavBarManagerDidBecomeFullyContracted:(TLYShyNavBarManager *) shyNavBarManager; +- (void)shyNavBarManagerDidStartContracting:(TLYShyNavBarManager *) shyNavBarManager; - (void)shyNavBarManagerDidFinishContracting:(TLYShyNavBarManager *) shyNavBarManager; +- (void)shyNavBarManagerDidBecomeFullyContracted:(TLYShyNavBarManager *) shyNavBarManager; + +- (void)shyNavBarManagerDidStartExpanding:(TLYShyNavBarManager *) shyNavBarManager; - (void)shyNavBarManagerDidFinishExpanding:(TLYShyNavBarManager *) shyNavBarManager; +- (void)shyNavBarManagerDidBecomeFullyExpanded:(TLYShyNavBarManager *) shyNavBarManager; @end diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index e430a35..43cc99b 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -37,6 +37,12 @@ @interface TLYShyNavBarManager () 0) + else if (self.scrollView.contentOffset.y > -self.bottom && !self.isMidTransition) { CGFloat availableResistance = self.expansionResistance - self.resistanceConsumed; self.resistanceConsumed = MIN(self.expansionResistance, self.resistanceConsumed + deltaY); @@ -328,11 +397,11 @@ - (void)_handleScrolling } else { visibleTop = MAX(maxNavY, maxExtensionY); } - if (visibleTop == self.statusBarController.calculateTotalHeightRecursively) { - if ([self.delegate respondsToSelector:@selector(shyNavBarManagerDidBecomeFullyContracted:)]) { - [self.delegate shyNavBarManagerDidBecomeFullyContracted:self]; - } - } + + self.startedContracting = deltaY < 0; + self.startedExpanding = deltaY > 0; + self.fullyContracted = visibleTop == self.statusBarController.calculateTotalHeightRecursively; + self.fullyExpanded = visibleTop == self.extensionController.calculateTotalHeightRecursively; [self.navBarController updateYOffset:deltaY]; } From 403e10f50eb875c39955eb2d56821abf5a749732 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Tue, 27 Sep 2016 11:42:10 -0400 Subject: [PATCH 20/24] Revert "removed applicationDidChangeStatusBarFrame" This reverts commit db5a1805677737906a53e7d8192b114df4ad6e9e. --- TLYShyNavBar/TLYShyNavBarManager.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 43cc99b..9c4cb50 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -107,6 +107,11 @@ - (instancetype)init selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidChangeStatusBarFrame:) + name:UIApplicationDidChangeStatusBarFrameNotification + object:nil]; } return self; } @@ -546,6 +551,11 @@ - (void)applicationDidBecomeActive:(NSNotification *)notification } } +- (void)applicationDidChangeStatusBarFrame:(NSNotification *)notification +{ + [self.navBarController expand]; +} + @end #pragma mark - UIViewController+TLYShyNavBar category From 1b0ac3a06f7b6adf19f1bb21695b40e743d9f44b Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Fri, 21 Oct 2016 10:30:43 -0400 Subject: [PATCH 21/24] removed `scrolling` property --- TLYShyNavBar/TLYShyNavBarManager.m | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 9c4cb50..432e9d8 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -43,7 +43,6 @@ @interface TLYShyNavBarManager () Date: Tue, 25 Oct 2016 15:03:11 -0400 Subject: [PATCH 22/24] cleanup for PR --- TLYShyNavBar/ShyControllers/TLYShyParent.h | 1 - .../TLYShyStatusBarController.m | 7 +- .../ShyControllers/TLYShyViewController.h | 19 +-- .../ShyControllers/TLYShyViewController.m | 57 ++++++-- TLYShyNavBar/TLYShyNavBarManager.h | 13 +- TLYShyNavBar/TLYShyNavBarManager.m | 124 +++++++++++++++--- 6 files changed, 160 insertions(+), 61 deletions(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyParent.h b/TLYShyNavBar/ShyControllers/TLYShyParent.h index a4a983c..d54fad6 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyParent.h +++ b/TLYShyNavBar/ShyControllers/TLYShyParent.h @@ -19,7 +19,6 @@ - (CGFloat)maxYRelativeToView:(UIView *)superview; - (CGFloat)calculateTotalHeightRecursively; -- (CGFloat)calculateBottomRecursively; @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m index 29d5447..1bd9772 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m @@ -20,7 +20,7 @@ static inline CGFloat AACStatusBarHeight(UIViewController *viewController) } // Modal views do not overlap the status bar, so no allowance need be made for it - if (viewController.presentingViewController != nil) + if (viewController.presentingViewController.presentedViewController == viewController) { return 0.f; } @@ -69,10 +69,5 @@ - (CGFloat)calculateTotalHeightRecursively return [self _statusBarHeight]; } -- (CGFloat)calculateBottomRecursively -{ - return [self _statusBarHeight]; -} - @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.h b/TLYShyNavBar/ShyControllers/TLYShyViewController.h index aef9087..b7c8490 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.h @@ -19,8 +19,6 @@ typedef CGPoint(^TLYShyViewControllerExpandedCenterBlock)(UIView *view); typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); -@protocol TLYShyViewControllerDelegate; - /* CLASS DESCRIPTION: * ================== * A shy view is a view that contracts when a scrolling event is @@ -40,17 +38,18 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic, weak) UIView *view; @property (nonatomic) TLYShyNavBarFade fadeBehavior; -@property (nonatomic) BOOL scaleBehaviour; @property (nonatomic, readonly) BOOL contracted; @property (nonatomic, readonly) BOOL expanded; +/* Scale means the navbar's subviews will scale as the navbar contracts/expands. + */ +@property (nonatomic) BOOL scale; + /* Sticky means it will always stay in expanded state */ @property (nonatomic) BOOL sticky; -@property (nonatomic, weak) id delegate; - - (void)offsetCenterBy:(CGPoint)deltaPoint; - (CGFloat)updateYOffset:(CGFloat)deltaY; @@ -63,15 +62,5 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @end -@protocol TLYShyViewControllerDelegate - -@optional - -- (void)shyViewControllerDidContract:(TLYShyViewController *) shyViewController; -- (void)shyViewControllerDidExpand:(TLYShyViewController *) shyViewController; - -@end - - @interface TLYShyViewController (AsParent) @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyViewController.m b/TLYShyNavBar/ShyControllers/TLYShyViewController.m index ad8e54d..75dcea4 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyViewController.m @@ -22,11 +22,7 @@ - (CGFloat)maxYRelativeToView:(UIView *)superview - (CGFloat)calculateTotalHeightRecursively { - float overlap = [self.parent maxYRelativeToView:self.view]; - if ([self.parent isMemberOfClass:[TLYShyStatusBarController class]] && overlap - self.view.frame.origin.y > 0) { - overlap += overlap - self.view.frame.origin.y; - } - return CGRectGetHeight(self.view.bounds) - overlap + [self.parent calculateTotalHeightRecursively]; + return (self.expanded ? CGRectGetHeight(self.view.bounds) : 0) + [self.parent calculateTotalHeightRecursively]; } @end @@ -39,9 +35,6 @@ @interface TLYShyViewController () @property (nonatomic, assign) CGPoint contractedCenterValue; -@property (nonatomic, assign) BOOL contracted; -@property (nonatomic, assign) BOOL expanded; - @end @implementation TLYShyViewController @@ -81,6 +74,12 @@ - (BOOL)expanded #pragma mark - Private methods +- (void)_onProgressUpdate:(CGFloat)progress +{ + [self _onAlphaUpdate:progress]; + [self _onScaleUpdate:progress]; +} + - (void)_onAlphaUpdate:(CGFloat)alpha { if (self.sticky) @@ -125,6 +124,32 @@ - (void)_updateSubviewsAlpha:(CGFloat)alpha } } +- (void)_onScaleUpdate:(CGFloat)scale +{ + if (self.sticky) + { + [self _updateSubviewsScale:1.f]; + return; + } + + [self _updateSubviewsScale:self.scale ? scale : 1.f]; +} + +- (void)_updateSubviewsScale:(CGFloat)scale +{ + if (![self.view isKindOfClass:[UINavigationBar class]]) + { + return; + } + + UINavigationBar *navigationBar = (UINavigationBar *)self.view; + + for (UIView* view in navigationBar.topItem.titleView.subviews) + { + view.transform = scale < 1 ? CGAffineTransformMakeScale(scale, scale) : CGAffineTransformIdentity; + } +} + - (void)_updateCenter:(CGPoint)newCenter { CGPoint currentCenter = self.view.center; @@ -146,6 +171,16 @@ - (void)setFadeBehavior:(TLYShyNavBarFade)fadeBehavior } } +- (void)setScale:(BOOL)scale +{ + _scale = scale; + + if (!scale) + { + [self _onScaleUpdate:1.f]; + } +} + - (void)offsetCenterBy:(CGPoint)deltaPoint { self.view.center = CGPointMake(self.view.center.x + deltaPoint.x, @@ -173,7 +208,7 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY CGFloat newAlpha = 1.f - (self.expandedCenterValue.y - self.view.center.y) / self.contractionAmountValue; newAlpha = MIN(MAX(FLT_EPSILON, newAlpha), 1.f); - [self _onAlphaUpdate:newAlpha]; + [self _onProgressUpdate:newAlpha]; residual = newYOffset - newYCenter; @@ -236,7 +271,7 @@ - (CGFloat)expand { self.view.hidden = NO; - [self _onAlphaUpdate:1.f]; + [self _onProgressUpdate:1.f]; CGFloat amountToMove = self.expandedCenterValue.y - self.view.center.y; @@ -250,7 +285,7 @@ - (CGFloat)contract { CGFloat amountToMove = self.contractedCenterValue.y - self.view.center.y; - [self _onAlphaUpdate:FLT_EPSILON]; + [self _onProgressUpdate:FLT_EPSILON]; [self _updateCenter:self.contractedCenterValue]; [self.subShyController contract]; diff --git a/TLYShyNavBar/TLYShyNavBarManager.h b/TLYShyNavBar/TLYShyNavBarManager.h index da34601..c27d4ad 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.h +++ b/TLYShyNavBar/TLYShyNavBarManager.h @@ -62,11 +62,7 @@ @property (nonatomic) CGFloat expansionResistance; // default 200 @property (nonatomic) CGFloat contractionResistance; // default 0 -/* The combined height of all the nav bar including the extension view and status bar - */ -@property (nonatomic, readonly) CGFloat height; - -/* Check the state of the control +/* Check the state of the control. */ @property (nonatomic, readonly) BOOL contracting; @@ -78,17 +74,12 @@ /* Choose if the navbar's subviews scale as the navbar contracts/expands. * Defaults to NO */ -@property (nonatomic) BOOL scaleBehavior; +@property (nonatomic) BOOL scale; /* Use this to set if the controller have any kind of custom refresh control */ @property (nonatomic) BOOL hasCustomRefreshControl; -/* Set this to true if you want this control to automatically adjust the scroll view insets - * Defaults to NO - */ -@property (nonatomic) BOOL automaticallyAdjustsScrollViewInsets; - /* Set NO to disable shyNavBar behavior temporarily. * Defaults to NO */ diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 63f3267..4f8b1f3 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -39,10 +39,16 @@ @interface TLYShyNavBarManager () @property (nonatomic, assign) CGFloat previousYOffset; @property (nonatomic, assign) CGFloat resistanceConsumed; +@property (nonatomic, assign) BOOL startedContracting; +@property (nonatomic, assign) BOOL startedExpanding; +@property (nonatomic, assign) BOOL fullyContracted; +@property (nonatomic, assign) BOOL fullyExpanded; + @property (nonatomic, assign) BOOL contracting; @property (nonatomic, assign) BOOL previousContractionState; @property (nonatomic, readonly) BOOL isViewControllerVisible; +@property (nonatomic, readonly) BOOL isPageViewController; @end @@ -58,6 +64,10 @@ - (instancetype)init self.delegateProxy = [[TLYDelegateProxy alloc] initWithMiddleMan:self]; /* Initialize defaults */ + self.startedContracting = NO; + self.startedExpanding = NO; + self.fullyContracted = NO; + self.fullyExpanded = YES; self.contracting = NO; self.previousContractionState = YES; @@ -65,6 +75,7 @@ - (instancetype)init self.contractionResistance = 0.f; self.fadeBehavior = TLYShyNavBarFadeSubviews; + self.scale = NO; self.previousYOffset = NAN; /* Initialize shy controllers */ @@ -80,7 +91,7 @@ - (instancetype)init self.extensionController.view = self.extensionViewContainer; /* hierarchy setup */ - /* StatusBar <-- navbar <-->> extension <--> scrollView + /* StatusBar <--> navbar <--> extension <--> scrollView */ self.navBarController.parent = self.statusBarController; self.navBarController.child = self.extensionController; @@ -167,10 +178,24 @@ - (void)setScrollView:(UIScrollView *)scrollView self.delegateProxy.originalDelegate = _scrollView.delegate; _scrollView.delegate = (id)self.delegateProxy; } + + if (self.isPageViewController) + { + UIEdgeInsets insets = UIEdgeInsetsMake(self.extensionController.calculateTotalHeightRecursively, + self.scrollView.contentInset.left, + self.scrollView.contentInset.bottom, + self.scrollView.contentInset.right); + + [self.scrollView tly_setInsets:insets]; - [self cleanup]; - [self layoutViews]; - + self.previousYOffset = NAN; + } + else + { + [self cleanup]; + [self layoutViews]; + } + [_scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:kTLYShyNavBarManagerKVOContext]; } @@ -184,6 +209,11 @@ - (BOOL)isViewControllerVisible return self.viewController.isViewLoaded && self.viewController.view.window; } +- (BOOL)isPageViewController +{ + return [self.viewController isKindOfClass:[UIPageViewController class]]; +} + - (void)setDisable:(BOOL)disable { if (disable == _disable) @@ -230,6 +260,66 @@ - (void)setStickyExtensionView:(BOOL)stickyExtensionView self.extensionController.sticky = stickyExtensionView; } +- (void)setStartedContracting:(BOOL)startedContracting +{ + if (_startedContracting == startedContracting) + { + return; + } + + _startedContracting = startedContracting; + + if (startedContracting && [self.delegate respondsToSelector:@selector(shyNavBarManagerDidStartContracting:)]) + { + [self.delegate shyNavBarManagerDidStartContracting:self]; + } +} + +- (void)setStartedExpanding:(BOOL)startedExpanding +{ + if (_startedExpanding == startedExpanding) + { + return; + } + + _startedExpanding = startedExpanding; + + if (startedExpanding && [self.delegate respondsToSelector:@selector(shyNavBarManagerDidStartExpanding:)]) + { + [self.delegate shyNavBarManagerDidStartExpanding:self]; + } +} + +- (void)setFullyContracted:(BOOL)fullyContracted +{ + if (_fullyContracted == fullyContracted) + { + return; + } + + _fullyContracted = fullyContracted; + + if (fullyContracted && [self.delegate respondsToSelector:@selector(shyNavBarManagerDidBecomeFullyContracted:)]) + { + [self.delegate shyNavBarManagerDidBecomeFullyContracted:self]; + } +} + +- (void)setFullyExpanded:(BOOL)fullyExpanded +{ + if (_fullyExpanded == fullyExpanded) + { + return; + } + + _fullyExpanded = fullyExpanded; + + if (fullyExpanded && [self.delegate respondsToSelector:@selector(shyNavBarManagerDidBecomeFullyExpanded:)]) + { + [self.delegate shyNavBarManagerDidBecomeFullyExpanded:self]; + } +} + #pragma mark - Private methods @@ -312,6 +402,7 @@ - (void)_handleScrolling // 6 - Update the navigation bar shyViewController self.navBarController.fadeBehavior = self.fadeBehavior; + self.navBarController.scale = self.scale; // 7 - Inform the delegate if needed CGFloat maxNavY = CGRectGetMaxY(self.navBarController.view.frame); @@ -322,11 +413,11 @@ - (void)_handleScrolling } else { visibleTop = MAX(maxNavY, maxExtensionY); } - if (visibleTop == self.statusBarController.calculateTotalHeightRecursively) { - if ([self.delegate respondsToSelector:@selector(shyNavBarManagerDidBecomeFullyContracted:)]) { - [self.delegate shyNavBarManagerDidBecomeFullyContracted:self]; - } - } + + self.startedContracting = deltaY < 0; + self.startedExpanding = deltaY > 0; + self.fullyContracted = visibleTop == self.statusBarController.calculateTotalHeightRecursively; + self.fullyExpanded = visibleTop == self.extensionController.calculateTotalHeightRecursively; [self.navBarController updateYOffset:deltaY]; } @@ -371,7 +462,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath { if (context == kTLYShyNavBarManagerKVOContext) { - if (self.isViewControllerVisible && ![self _scrollViewIsSuffecientlyLong]) + if (!self.isPageViewController && self.isViewControllerVisible && ![self _scrollViewIsSuffecientlyLong]) { [self.navBarController expand]; } @@ -409,11 +500,6 @@ - (void)setExtensionView:(UIView *)view } } -- (void)prepareForDisplay -{ - [self cleanup]; -} - - (void)layoutViews { if (fabs([self.scrollViewController updateLayoutIfNeeded]) > FLT_EPSILON) @@ -493,13 +579,17 @@ + (void)load - (void)tly_swizzledViewWillAppear:(BOOL)animated { - [[self _internalShyNavBarManager] prepareForDisplay]; + [[self _internalShyNavBarManager] cleanup]; [self tly_swizzledViewWillAppear:animated]; } - (void)tly_swizzledViewDidLayoutSubviews { - [[self _internalShyNavBarManager] layoutViews]; + if (![self _internalShyNavBarManager].isPageViewController) + { + [[self _internalShyNavBarManager] layoutViews]; + } + [self tly_swizzledViewDidLayoutSubviews]; } From e6f3d3ec13ab690124eb64f0b87f8cba71812442 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Tue, 24 Jan 2017 11:26:26 -0500 Subject: [PATCH 23/24] fix top inset when setting scroll view --- TLYShyNavBar/TLYShyNavBarManager.m | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 4f8b1f3..daec607 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -187,15 +187,10 @@ - (void)setScrollView:(UIScrollView *)scrollView self.scrollView.contentInset.right); [self.scrollView tly_setInsets:insets]; - - self.previousYOffset = NAN; - } - else - { - [self cleanup]; - [self layoutViews]; } + self.previousYOffset = NAN; + [_scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:kTLYShyNavBarManagerKVOContext]; } From 3e5db74420e40f265daeba3c407fd9f8cc6d9ae8 Mon Sep 17 00:00:00 2001 From: Cole Dunsby Date: Fri, 21 Apr 2017 11:34:38 -0400 Subject: [PATCH 24/24] removed viewOverlapsStatusBar check --- TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m | 7 ------- 1 file changed, 7 deletions(-) diff --git a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m index 1bd9772..dc1b63e 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m @@ -31,13 +31,6 @@ static inline CGFloat AACStatusBarHeight(UIViewController *viewController) 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; }