
上滑隱藏navigationBar
在需要上滑隱藏的tableView或者scrollView中,實(shí)現(xiàn)scrollViewWillEndDragging方法:
首先在控制器中設(shè)一個(gè)保存上一個(gè)偏移量的屬性:
TestTableViewController:
fileprivate var tempY: CGFloat = -64
override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if velocity.y > 0 || scrollView.contentOffset.y > self.tempY {
self.navigationController?.setNavigationBarHidden(true, animated: true)
} else {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
self.tempY = scrollView.contentOffset.y
}