From e1fba0efa7de9679c151cabde7242a7a9421020f Mon Sep 17 00:00:00 2001 From: Gian Franco Zabarino Date: Fri, 29 Jan 2016 22:04:14 -0300 Subject: [PATCH] - Fixed bug in which the bounds / contentOffset of the scroll view wasn't being updated on some occasions. --- TLYShyNavBar/Categories/UIScrollView+Helpers.h | 2 +- TLYShyNavBar/Categories/UIScrollView+Helpers.m | 4 ++-- TLYShyNavBar/ShyControllers/TLYShyScrollViewController.h | 2 +- TLYShyNavBar/ShyControllers/TLYShyScrollViewController.m | 8 ++++---- TLYShyNavBar/TLYShyNavBarManager.m | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TLYShyNavBar/Categories/UIScrollView+Helpers.h b/TLYShyNavBar/Categories/UIScrollView+Helpers.h index ed2ca1c..ca3c906 100644 --- a/TLYShyNavBar/Categories/UIScrollView+Helpers.h +++ b/TLYShyNavBar/Categories/UIScrollView+Helpers.h @@ -11,6 +11,6 @@ @interface UIScrollView (Helpers) -- (void)tly_setInsets:(UIEdgeInsets)contentInsets preserveOffset:(BOOL)preserveOffset; +- (void)tly_setInsets:(UIEdgeInsets)contentInsets; @end diff --git a/TLYShyNavBar/Categories/UIScrollView+Helpers.m b/TLYShyNavBar/Categories/UIScrollView+Helpers.m index 214ec06..4de4f92 100644 --- a/TLYShyNavBar/Categories/UIScrollView+Helpers.m +++ b/TLYShyNavBar/Categories/UIScrollView+Helpers.m @@ -11,9 +11,9 @@ @implementation UIScrollView (Helpers) // Modify contentInset and scrollIndicatorInsets -- (void)tly_setInsets:(UIEdgeInsets)contentInsets preserveOffset:(BOOL)preserveOffset +- (void)tly_setInsets:(UIEdgeInsets)contentInsets { - if (preserveOffset && contentInsets.top != self.contentInset.top) + if (!self.isDragging && !self.isDecelerating && contentInsets.top != self.contentInset.top) { CGFloat offsetDelta = contentInsets.top - self.contentInset.top; diff --git a/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.h b/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.h index dc3b82f..ee81d81 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.h +++ b/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.h @@ -17,6 +17,6 @@ @property (nonatomic, weak) UIScrollView *scrollView; @property (nonatomic, weak) TLYShyViewController *parent; -- (CGFloat)updateLayoutIfNeeded:(BOOL)intelligently; +- (CGFloat)updateLayoutIfNeeded; @end diff --git a/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.m b/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.m index 789c0a7..1ee0f17 100644 --- a/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.m +++ b/TLYShyNavBar/ShyControllers/TLYShyScrollViewController.m @@ -14,10 +14,10 @@ - (void)offsetCenterBy:(CGPoint)deltaPoint { - [self updateLayoutIfNeeded:NO]; + [self updateLayoutIfNeeded]; } -- (CGFloat)updateLayoutIfNeeded:(BOOL)intelligently +- (CGFloat)updateLayoutIfNeeded { if (self.scrollView.contentSize.height < FLT_EPSILON && ([self.scrollView isKindOfClass:[UITableView class]] @@ -35,7 +35,7 @@ if (normalizedY > -FLT_EPSILON && !UIEdgeInsetsEqualToEdgeInsets(insets, self.scrollView.contentInset)) { CGFloat delta = insets.top - self.scrollView.contentInset.top; - [self.scrollView tly_setInsets:insets preserveOffset:intelligently]; + [self.scrollView tly_setInsets:insets]; return delta; } @@ -46,7 +46,7 @@ frame = UIEdgeInsetsInsetRect(frame, insets); self.scrollView.frame = frame; - return [self updateLayoutIfNeeded:YES]; + return [self updateLayoutIfNeeded]; } return 0.f; diff --git a/TLYShyNavBar/TLYShyNavBarManager.m b/TLYShyNavBar/TLYShyNavBarManager.m index c18c7b9..ba693c0 100644 --- a/TLYShyNavBar/TLYShyNavBarManager.m +++ b/TLYShyNavBar/TLYShyNavBarManager.m @@ -394,7 +394,7 @@ static void * const kTLYShyNavBarManagerKVOContext = (void*)&kTLYShyNavBarManage - (void)layoutViews { - if (fabs([self.scrollViewController updateLayoutIfNeeded:YES]) > FLT_EPSILON) + if (fabs([self.scrollViewController updateLayoutIfNeeded]) > FLT_EPSILON) { [self.navBarController expand]; [self.extensionViewContainer.superview bringSubviewToFront:self.extensionViewContainer];