diff --git a/TLYShyNavBar/TLYShyNavBarController.m b/TLYShyNavBar/TLYShyNavBarController.m index 295475c..fa2b55c 100644 --- a/TLYShyNavBar/TLYShyNavBarController.m +++ b/TLYShyNavBar/TLYShyNavBarController.m @@ -140,7 +140,10 @@ static const CGFloat contractionVelocity = 140.f; deltaY = MAX(0, deltaY - self.previousYOffset + end); } - self.isContracting = deltaY < 0; + if (fabs(deltaY) > FLT_EPSILON) + { + self.isContracting = deltaY < 0; + } deltaY = [(self.isContracting ? self.extensionController : self.navBarController) updateYOffset:deltaY]; [(self.isContracting ? self.navBarController : self.extensionController) updateYOffset:deltaY]; @@ -151,8 +154,11 @@ static const CGFloat contractionVelocity = 140.f; - (void)_handleScrollingEnded { + TLYShyViewController *first = (self.isContracting ? self.extensionController : self.navBarController); + TLYShyViewController *second = (self.isContracting ? self.navBarController : self.extensionController); - CGFloat deltaY = 0.f; + CGFloat deltaY = [first snap:self.isContracting]; + deltaY += [second snap:self.isContracting]; CGPoint newContentOffset = self.scrollView.contentOffset; newContentOffset.y -= deltaY; diff --git a/TLYShyNavBar/TLYShyViewController.m b/TLYShyNavBar/TLYShyViewController.m index e8c0302..dbc0123 100644 --- a/TLYShyNavBar/TLYShyViewController.m +++ b/TLYShyNavBar/TLYShyViewController.m @@ -62,11 +62,14 @@ - (CGFloat)snap:(BOOL)contract { - CGFloat deltaY = (contract - ? self.expandedCenterValue.y - self.view.center.y - : self.expandedCenterValue.y - self.contractionAmountValue); + CGFloat newYCenter = (contract + ? self.expandedCenterValue.y - self.contractionAmountValue + : self.expandedCenterValue.y); - return [self updateYOffset:deltaY]; + CGFloat deltaY = newYCenter - self.view.center.y; + [self updateYOffset:deltaY]; + + return deltaY; } - (void)expand