From d97164f7284d55b3fb43d6c84c8256af3ee2cc5f Mon Sep 17 00:00:00 2001 From: Mazyad Alabduljaleel Date: Tue, 15 Jul 2014 14:18:17 +0400 Subject: [PATCH] [FIX]: don't handle the scrolling if the content size of the scroll view is insufficiently long. #12 --- TLYShyNavBar/TLYShyNavBarManager.m | 11 ++++++++++- TLYShyNavBar/TLYShyViewController.h | 2 ++ TLYShyNavBar/TLYShyViewController.m | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index 3f54c07..518d8c0 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -152,9 +152,18 @@ static inline CGFloat AACStatusBarHeight() #pragma mark - Private methods +- (BOOL)_shouldHandleScrolling +{ + CGRect scrollFrame = UIEdgeInsetsInsetRect(self.scrollView.bounds, self.scrollView.contentInset); + CGFloat scrollableAmount = self.scrollView.contentSize.height - CGRectGetHeight(scrollFrame); + BOOL scrollViewIsSuffecientlyLong = (scrollableAmount > self.navBarController.totalHeight); + + return (self.isViewControllerVisible && scrollViewIsSuffecientlyLong); +} + - (void)_handleScrolling { - if (!self.isViewControllerVisible) + if (![self _shouldHandleScrolling]) { return; } diff --git a/TLYShyNavBar/TLYShyViewController.h b/TLYShyNavBar/TLYShyViewController.h index 5d0bc71..1a7451d 100644 --- a/TLYShyNavBar/TLYShyViewController.h +++ b/TLYShyNavBar/TLYShyViewController.h @@ -35,6 +35,8 @@ typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view); @property (nonatomic) BOOL hidesSubviews; @property (nonatomic) BOOL hidesAfterContraction; +@property (nonatomic, readonly) CGFloat totalHeight; + - (CGFloat)updateYOffset:(CGFloat)deltaY; - (CGFloat)snap:(BOOL)contract; diff --git a/TLYShyNavBar/TLYShyViewController.m b/TLYShyNavBar/TLYShyViewController.m index 9616df9..b09f610 100644 --- a/TLYShyNavBar/TLYShyViewController.m +++ b/TLYShyNavBar/TLYShyViewController.m @@ -24,6 +24,8 @@ const CGFloat contractionVelocity = 300.f; @implementation TLYShyViewController +#pragma mark - Properties + // convenience - (CGPoint)expandedCenterValue { @@ -50,6 +52,13 @@ const CGFloat contractionVelocity = 300.f; return fabs(self.view.center.y - self.expandedCenterValue.y) < FLT_EPSILON; } +- (CGFloat)totalHeight +{ + return self.child.totalHeight + (self.expandedCenterValue.y - self.contractedCenterValue.y); +} + +#pragma mark - Private methods + // This method is courtesy of GTScrollNavigationBar // https://github.com/luugiathuy/GTScrollNavigationBar - (void)_updateSubviewsToAlpha:(CGFloat)alpha @@ -66,6 +75,8 @@ const CGFloat contractionVelocity = 300.f; } } +#pragma mark - Public methods + - (CGFloat)updateYOffset:(CGFloat)deltaY { if (self.child && deltaY < 0)