如何在iOS 11中更改navigationBar高度? [英] How to change navigationBar height in iOS 11?

查看:116
本文介绍了如何在iOS 11中更改navigationBar高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,更改navigationBar高度面临iOS 11中的新方法。在以前的iOS版本中,可以通过隐藏默认的navigationBar并添加带有自定义框架的新导航栏来更改navigationBar高度:

Apparently changing the navigationBar height faced a new approach in iOS 11. in previous iOS versions it was possible to change the navigationBar height by hiding the default navigationBar and adding a new one with custom frame:

self.navigationController?.setNavigationBarHidden(true, animated: false)
let customNavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 64))
self.view.addSubview(customNavigationBar)

但它似乎无法在iOS 11 xCode beta中运行。无论新的高度是多少,它总是保持在44。

But it seems that it is not working in iOS 11 xCode beta. no matter what the new height is, it will always stay at 44.

这是我在xCode 9中得到的:

this is what I've got in xCode 9:

有谁知道如何解决问题?

does anyone know how to solve the problem?

推荐答案

你的代码运行正常,它没有错。如果您更改 customNavigationBar 的背景颜色,您将看到您将获得具有所需高度的导航栏。但似乎是Xcode 9隐藏默认导航栏的问题。

Your code is working fine and it´s nothing wrong with it. If you change the background color of your customNavigationBar you´ll see that you´ll get the navigation bar with the desired height. But it seems like it´s an issue with Xcode 9 to hide the default navigation bar.

您的代码:


Xcode 9

Your code with:

Xcode 9

Xcode 8

正如您在Xcode 9图像中看到的那样,您有自定义导航栏,但默认导航栏不会隐藏。可能是Xcode 9中的一个错误,我也无法通过Storyboard隐藏它。

As you can see in the Xcode 9 image, you have the custom navigation bar but the default one does not hide. Probably a bug in Xcode 9, I did not manage to hide it through the Storyboard either.

这似乎是Xcode 9中的一个错误,错误报告已经已经提交给Apple。

这篇关于如何在iOS 11中更改navigationBar高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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