有navigationbar和没有navigationbar的Bug

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

屏幕快照 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吗?
  • 如果你知道为啥,还麻烦写下,告诉更多的人,在此谢谢~~
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容