Skip to content

Commit

Permalink
Merge pull request #310 from p-kislitskiy/hideNavbar_fix
Browse files Browse the repository at this point in the history
Fix hideNavbar method
  • Loading branch information
andreamazz authored Apr 11, 2018
2 parents ae552b7 + 5179820 commit 6bc0954
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Source/ScrollingNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 6bc0954

Please sign in to comment.