From 51798209ccd5527829e6839c4b55324a177c4b58 Mon Sep 17 00:00:00 2001 From: Pavel Kislitskiy Date: Wed, 4 Apr 2018 12:19:50 +0300 Subject: [PATCH] fix hideNavbar method --- Source/ScrollingNavigationController.swift | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Source/ScrollingNavigationController.swift b/Source/ScrollingNavigationController.swift index 5de78d8b..92bdd23d 100644 --- a/Source/ScrollingNavigationController.swift +++ b/Source/ScrollingNavigationController.swift @@ -162,20 +162,31 @@ open class ScrollingNavigationController: UINavigationController, UIGestureRecog open func hideNavbar(animated: Bool = true, duration: TimeInterval = 0.1) { guard let _ = self.scrollableView, let visibleViewController = self.visibleViewController else { return } - if state == .expanded { - self.state = .scrolling - UIView.animate(withDuration: animated ? duration : 0, animations: { () -> Void in - self.scrollWithDelta(self.fullNavbarHeight) - visibleViewController.view.setNeedsLayout() - if self.navigationBar.isTranslucent { - let currentOffset = self.contentOffset - self.scrollView()?.contentOffset = CGPoint(x: currentOffset.x, y: currentOffset.y + self.navbarHeight) - } - }) { _ in + guard state == .expanded else { + updateNavbarAlpha() + return + } + + gestureRecognizer?.isEnabled = false + let animations = { + self.scrollWithDelta(self.fullNavbarHeight, ignoreDelay: true) + visibleViewController.view.setNeedsLayout() + if self.navigationBar.isTranslucent { + let currentOffset = self.contentOffset + self.scrollView()?.contentOffset = CGPoint(x: currentOffset.x, y: currentOffset.y + self.navbarHeight) + } + } + + if animated { + state = .scrolling + UIView.animate(withDuration: duration, animations: animations) { _ in self.state = .collapsed + self.gestureRecognizer?.isEnabled = true } } else { - updateNavbarAlpha() + animations() + state = .collapsed + gestureRecognizer?.isEnabled = true } }