如何向下滚动隐藏导航栏和工具栏? Swift(喜欢myBridge应用程序) [英] How to hide the navigation bar and toolbar as scroll down? Swift (like myBridge app)

查看:211
本文介绍了如何向下滚动隐藏导航栏和工具栏? Swift(喜欢myBridge应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在向下滚动页面时隐藏工具栏和导航栏。当我向上滚动时返回它。这怎么可能?

I want to hide a toolbar and nav bar as I scroll down a page. And return it as I scroll up. How is this possible?

我如何检测阻力?我是否使用平移手势或是滚动视图?

How would I go about detecting the drag? Do I use pan gesture or is this down with the scrollview?

推荐答案

尝试这种简单方法:在 Swift 3

Try this simple approach: Tested in Swift 3

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

    if(velocity.y>0) {
        //Code will work without the animation block.I am using animation block incase if you want to set any delay to it.
        UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { 
            self.navigationController?.setNavigationBarHidden(true, animated: true) 
            self.navigationController?.setToolbarHidden(true, animated: true)
            print("Hide")
        }, completion: nil)

    } else {
        UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { 
            self.navigationController?.setNavigationBarHidden(false, animated: true)
            self.navigationController?.setToolbarHidden(false, animated: true)
            print("Unhide")
        }, completion: nil)    
      }
   }

输出: 已更新

注意:如果您将此VC中的任何数据传递到另一个嵌入了 navigationController 的VC。您可能需要取消隐藏 NavigationBar

Note: If you passing any data from this VC to another VC that embedded with navigationController.You may need to unhide the NavigationBar.

这篇关于如何向下滚动隐藏导航栏和工具栏? Swift(喜欢myBridge应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆