private var historyY: CGFloat? // 哈哈
下拉,就 隐藏 tabbar
extension FindViewController {
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if historyY != nil {
//参考 OC 的, if (_historyY+20<targetContentOffset->y)
if historyY! + 20 < targetContentOffset.memory.y {
self.setTabBarHidden(true)
} else if historyY! - 20 < targetContentOffset.memory.y {
self.setTabBarHidden(false)
}
}
historyY = targetContentOffset.memory.y
}
```
func setTabBarHidden(hidden: Bool) {
let tabView = (self.tabBarController?.view)!
var tabRect = self.tabBarController?.tabBar.frame
if ( tabView.subviews.count < 2 ) {
return
}
var view = UIView()
if tabView.subviews[0].isKindOfClass(UITabBar.self) {
view = tabView.subviews[1]
} else {
view = tabView.subviews[0]
}
if (hidden == true) {
view.frame = tabView.bounds
tabRect?.origin.y = kScreenHeight + (self.tabBarController?.tabBar.frame.size.height)!
} else {
view.frame = CGRectMake(tabView.bounds.origin.x, tabView.bounds.origin.y, tabView.bounds.size.width, tabView.bounds.size.height)
tabRect?.origin.y = kScreenHeight - (self.tabBarController?.tabBar.frame.size.height)!
}
UIView.animateWithDuration(0.5) {
self.tabBarController?.tabBar.frame = tabRect!
}
}
> }