Swift 调用 setNavigationBarHidden 但视图不会移到顶部 [英] Swift calling setNavigationBarHidden but view wont move to top

查看:40
本文介绍了Swift 调用 setNavigationBarHidden 但视图不会移到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过调用滚动时隐藏我的导航栏:self.navigationController?.setNavigationBarHidden(true, animated: true)

I am hiding my navigation bar when I scroll by calling: self.navigationController?.setNavigationBarHidden(true, animated: true)

唯一的问题是导航栏没有完全隐藏.

The only problem is that the navbar doesnt get hidden all the way.

更奇怪的是,如果我推到一个新的 VC 并返回,现在尝试滚动导航栏会一直隐藏,这正是我想要的.

Whats even stranger is if I push to a new VC and go back and now try to scroll the navigation bar gets hidden all the way which is what I want.

如果重要的话,我会在 VC2 上隐藏导航栏,然后在我退出到 VC 1 时显示它.

If it matters I am hiding the navigation bar on VC2 then showing it when I exit back to VC 1.

这是我第一次尝试隐藏导航栏时的样子,它不会一直向上/底层视图显示太多.

This is what it looks when I try to hide the navbar first time, it doesnt go up all the way/underlying view showing too much.

如果我推到下一个 VC 并返回并现在尝试隐藏导航栏,它可以工作

If I push the to next VC and go back and now try to hide the navigationbar it works

我的视图对顶部布局有 0 的约束,因此它拥抱顶部

The my view has a constraint of 0 to top layout so its hugging the top

那么在隐藏导航栏时,如何让我的视图始终像第二张图片一样?

So how can I make my view always be like in the second image when hiding my navigation bar?

推荐答案

试试这个代码...

注意:这是解决您的问题的简单方法.如果您想要更多自定义外观导航栏和状态栏外观.您应该阅读我之前的评论...

Note: This is a simple approach for your problem. If you want more custom look navBar and status bar look .You should read my previous comment...

将导航控制器属性 hidesBarsOnSwipe 设置为 true

Set navigation controller property hidesBarsOnSwipe to true

     override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

navigationController?.hidesBarsOnSwipe = true

}

这篇关于Swift 调用 setNavigationBarHidden 但视图不会移到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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