美文网首页
有navigationbar和没有navigationbar的B

有navigationbar和没有navigationbar的B

作者: coderST | 来源:发表于2017-07-12 10:45 被阅读15次

为了说明白问题,先看下层级图 .如下

屏幕快照 2017-07-12 10.25.58.png
  • 我在TwoVC里写了下面的方法
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: false)
        
    }

  • 但是如果你要是实现了全屏POP,在从TwoVC-1拖拽到TwoVC界面的时候,navigationBar会出现混乱问题

  • 于是我改为下面的方法

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: true)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: true)
        
    }

  • pop的问题解决了,但是当我在OneVCTwoVC来回切换的时候发现,TwoVC会下移一下,顿时整个人就不好了!!!

  • 于是发现官方文档解释(隐藏或显示导航栏。 如果动画,它将使用UINavigationControllerHideShowBarDuration进行垂直转换。)

Hide or show the navigation bar. If animated, it will transition vertically using UINavigationControllerHideShowBarDuration.

  • 最后改为下面的方法
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: animated)
        
    }

完美解决问题 false -> true -> animated

  • 不是很清楚为什么改为true不行,改为animated就可以了,不都是BOOL吗?
  • 如果你知道为啥,还麻烦写下,告诉更多的人,在此谢谢~~

相关文章

网友评论

      本文标题:有navigationbar和没有navigationbar的B

      本文链接:https://www.haomeiwen.com/subject/fiavhxtx.html