Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?

前端 未结 4 998
执笔经年
执笔经年 2020-12-23 23:41

I would like to hide both bars on scroll down on my iPhone. When I scroll up, they should appear again.. How can I handle this?

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 00:16

    Here's my solution in Swift; it works beautifully

    func scrollViewDidScroll(scrollView: UIScrollView) {
        let navController: UINavigationController = self.navigationController!
        if self.collectionView.panGestureRecognizer.translationInView(self.view).y <= 0.0 {
            defaultCenter.postNotificationName("stuffShouldHide", object: self)
        } else {
            defaultCenter.postNotificationName("stuffShouldUnhide", object: self)
        }
    }
    

提交回复
热议问题