【发布时间】:2018-10-18 07:52:13
【问题描述】:
我的 VC 有一个 tabBarController,我希望在滚动 tableView 时隐藏/显示取决于滚动。
我已经实现了以下方法:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
//scrolling down
changeTabBar(hidden: true, animated: true)
}
else{
//scrolling up
changeTabBar(hidden: false, animated: true)
}
}
func changeTabBar(hidden:Bool, animated: Bool){
let tabBar = self.tabBarController?.tabBar
let offset = (hidden ? UIScreen.main.bounds.size.height : UIScreen.main.bounds.size.height - (tabBar?.frame.size.height)! )
if offset == tabBar?.frame.origin.y {return}
self.mainCollectionView.frame.size.height = self.mainCollectionView.frame.size.height + (tabBarController?.tabBar.frame.size.height)!
let duration:TimeInterval = (animated ? 0.5 : 0.0)
UIView.animate(withDuration: duration,
animations: {tabBar!.frame.origin.y = offset},
completion:nil)
}
但我认为这与 self.mainCollectionView.frame.size.height = self.mainCollectionView.frame.size.height + (tabBarController?.tabBar.frame.size.height)! 有关。在该函数中调用它。我不知道。有时它确实有效,有时它是一个黑色的 tabBar 并且它也弄乱了我的滚动。有时我无法再滚动了.. 但如果我评论它,它工作正常
【问题讨论】:
-
尝试不使用动画
-
没有解决我的问题..我试过
标签: ios objective-c swift swift3 uitabbarcontroller