问题
I created a ViewController with TableView inside it and embedded it a NavigationController. I also set the constraints. On Swipe down, Navigation Bar hides. Everything seems fine.
The only problem is that on Swipe Up, the Navigation Bar doesn't come back.
If I use the same TableView with a TableViewController instead of ViewController (embedded from the same Navigation Controller), the Navigation Bar does comes back.
For the ones wondering why I don't just go with the TableViewController, because I need to uncheck Adjust Scroll View Insets for some disturbing bug.
回答1:
To solve the issue, I used scrollViewWillEndDragging and detected Going Down & Going Up
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if targetContentOffset.memory.y < scrollView.contentOffset.y {
// UP
} else {
// DOWN
}
}
回答2:
Here's my solution, based on senty's answer:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let draggDelta = scrollView.contentOffset.y - targetContentOffset.pointee.y
let hiddenContentHeight = spreadsheetView.contentSize.height - spreadsheetView.frame.height - 1
if 0 < draggDelta && targetContentOffset.pointee.y < hiddenContentHeight || (targetContentOffset.pointee.y == 0 && scrollView.contentOffset.y < 0) {
// Shows Navigation Bar
navigationController?.setNavigationBarHidden(false, animated: true)
}
}
来源:https://stackoverflow.com/questions/36511568/navigation-bar-doesnt-come-back-once-it-hides-swipe