我想在集合视图的顶部创建一个菜单栏。当用户向下滚动时,菜单栏将逐渐隐藏,而当用户向上滚动时,菜单栏将立即出现。行为类似于导航栏的hidewhenswipe擦除功能。在这个菜单栏上创建这样的行为有什么解决方案吗?谢谢。
屏幕截图
发布于 2018-07-05 12:32:38
@IBOutlet弱var scrollViewDidScroll:在ViewDidLoad()
函数scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView.contentOffset.y > 50 {//希望头视图隐藏view.layoutIfNeeded() headerViewHeightConstraint.constant =0 UIView.animate(withDuration: 0.5,delay: 0,options:.allowUserInteraction,animations:{ self.view.layoutIfNeeded() },completion: nil) }else { //展开header view.layoutIfNeeded() headerViewHeightConstraint.constant = 100 //您的header视图UIView.animate的初始高度(withDuration: 0.5,delay: 0,options:.allowUserInteraction,动画:{ self.view.layoutIfNeeded() },completion: nil) } }
发布于 2018-07-05 10:51:49
我一直在使用HidingNavigationBarManager来做你刚才描述的事情,它非常容易使用。如果您的ViewController中有一个tableView,那么只需将这些代码行添加到您的代码中就可以了。
var hidingNavBarManager: HidingNavigationBarManager?
...
...
override func viewDidLoad() {
super.viewDidLoad()
self.hidingNavBarManager = HidingNavigationBarManager(viewController: self, scrollView: tableView)
}
https://stackoverflow.com/questions/51182622
复制相似问题