iOS 上滑隱藏導航,下滑顯示導航,仿鬥魚導航效果

UItableView或 UIcollectionView 都是繼承UIScrollView 滑動的時候,判斷是上滑仍是下滑 使用 UIScrollView 的代理方法佈局

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) post

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        let pan = scrollView.panGestureRecognizer
        let velocity = pan.velocity(in: scrollView).y
        
        if velocity < -15 {
            //上滑
            self.navigationController?.setNavigationBarHidden(true, animated: true)
            //狀態欄顏色爲黑色
            UIApplication.shared.statusBarStyle = .default
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: kUpdateTitleFreamNote), object: nil)
            
        } else if velocity > 15 {
            //下滑
            self.navigationController?.setNavigationBarHidden(false, animated: true)
            //狀態欄顏色爲白色
            UIApplication.shared.statusBarStyle = .lightContent
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: kInUpdateTitleFreamNote), object: nil)
        }
    }

 上滑時狀態欄顏色爲黑色,導航隱藏,下滑導航欄顯示,狀態欄變爲白色spa

至於控件的佈局須要根據狀態去改變,3d

相關文章
相關標籤/搜索