How to get UIScrollView vertical direction in Swift?

前端 未结 12 1011
悲&欢浪女
悲&欢浪女 2020-12-01 01:51

How can I get the scroll/swipe direction for up/down in a VC?

I want to add a UIScrollView or something else in my VC that can see if the user swipes/scrolls up or d

12条回答
  •  旧时难觅i
    2020-12-01 02:29

    Simply add this method to your view controller:

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if (scrollView.contentOffset.y < 0) {
            // Move UP - Show Navigation Bar
            self.navigationController?.setNavigationBarHidden(false, animated: true)
        } else if (scrollView.contentOffset.y > 0) {
            // Move DOWN - Hide Navigation Bar
            self.navigationController?.setNavigationBarHidden(true, animated: true)
        }
    }
    

提交回复
热议问题