UI: scrollView 与 tabBar

    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!
        
        
        
        
    }
    
    
}

> }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容