Lyn*_*Kay 25 uinavigationbar uitoolbar ios swift
我想在向下滚动页面时隐藏工具栏和导航栏.当我向上滚动时返回它.这怎么可能?
我该如何检测阻力?我是否使用平移手势或滚动视图?
Joe*_*Joe 80
试试这个简单的方法:测试 Swift 3
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if(velocity.y>0) {
//Code will work without the animation block.I am using animation block incase if you want to set any delay to it.
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.navigationController?.setToolbarHidden(true, animated: true)
print("Hide")
}, completion: nil)
} else {
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.setToolbarHidden(false, animated: true)
print("Unhide")
}, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
输出: Updated
注意:如果你从这个VC传递任何数据到嵌入另一个VC navigationController.你可能需要unhide的NavigationBar.
Huu*_*yen 19
很容易做到这一点:
navigationController?.hidesBarsOnSwipe = true
Run Code Online (Sandbox Code Playgroud)
rak*_*hNS 11
在我看来,在 Tableview 中处理导航栏的正确方法如下。如果我们在 Tableview 中有节标题,这将适用。
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0 {
navigationController?.setNavigationBarHidden(true, animated: true)
} else {
navigationController?.setNavigationBarHidden(false, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢大家,我采用的方式是使用AMScrollingController.
https://github.com/andreamazz/AMScrollingNavbar
它已针对Swift 3进行了更新
| 归档时间: |
|
| 查看次数: |
30571 次 |
| 最近记录: |