ios iPhone X 的顶栏高度是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46197660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:27:04  来源:igfitidea点击:

What is the top bar height of iPhone X?

iosxcodeiphone-x

提问by IKKA

I would like to know exact height of top bar of iPhone X. Could you please mention the status bar and navigation bar height of iPhone X.Please help me.

我想知道 iPhone X 顶栏的确切高度。能否请您提及 iPhone X 的状态栏和导航栏高度。请帮助我。

enter image description here

在此处输入图片说明

回答by Anbu.Karthik

The display on iPhone X, however, is 145pttaller than a 4.7" display, resulting in roughly 20% additional vertical space for content.

然而,iPhone X 上的显示屏比 4.7 英寸显示屏高145 磅,从而为内容增加了大约 20% 的垂直空间。

for more information you get HIG for iphone X from apple documentsand detail description in here1and here2

有关更多信息,您可以从苹果文档此处1此处2 中的详细说明中获得 iPhone X 的 HIG

enter image description here

在此处输入图片说明

status bar height

状态栏高度

previously 20pt, now 44pt

以前是 20pt,现在是 44pt

Because of the sensors on top of the display, the new status bar is split in 2 parts. If your UI is doing something special with that space (previously 20pt high, now 44pt), because it will be taller on the iPhone X. Make sure that it can be dynamically changed in height. A great thing is that the height won't be changed if a user makes a phone call or is using a navigation app, which was previously the case on other iPhones.

由于显示屏顶部的传感器,新的状态栏分为两部分。如果你的 UI 对那个空间做了一些特别的处理(以前是 20pt 高,现在是 44pt),因为它在 iPhone X 上会更高。确保它可以动态改变高度。一个很棒的事情是,如果用户拨打电话或使用导航应用程序,高度不会改变,以前在其他 iPhone 上都是这种情况。

enter image description here

在此处输入图片说明

portrait

肖像

Navigation bar heightas normal 88and large title time 140

导航栏高度为正常88和大标题时间140

  • Standard title - 44pt (88pt with Status Bar)
  • Large title - 140pt
  • bottom bar - 34pt
  • 标准标题 - 44pt(88pt 带状态栏)
  • 大标题 - 140pt
  • 底部栏 - 34pt

Landscape

风景

  • Standard title - 32pt
  • bottom bar - 21pt
  • 标准标题 - 32pt
  • 底部栏 - 21pt

回答by skensell

Nav bar is 44pt as usual (when no large titles) and the status bar has increased from 20pt to 44pt. Here's what you can type in the debugger to verify it:

导航栏像往常一样是 44pt(没有大标题时),状态栏从 20pt 增加到 44pt。您可以在调试器中输入以下内容进行验证:

enter image description here

在此处输入图片说明

回答by jkira

You can use the navigation bar's .frame property to figure out the overall height of the top bar area:

您可以使用导航栏的 .frame 属性来计算顶部栏区域的整体高度:

Swift 5.0:

斯威夫特 5.0:

let xBarHeight = (self.navigationController?.navigationBar.frame.size.height ?? 0.0) + (self.navigationController?.navigationBar.frame.origin.y ?? 0.0)

ObjC:

对象:

CGRect navbarFrame = self.navigationController.navigationBar.frame;
float topWidth  = navbarFrame.size.width;
float topHeight = navbarFrame.size.height + navbarFrame.origin.y;

I suppose this is a bit of a cheat, but adding the navbar's height with its y origin seems to give the correct total height regardless of device.

我想这有点作弊,但是无论设备如何,将导航栏的高度与其 y 原点相加似乎都能给出正确的总高度。

回答by Paolo

You can programmatically obtain the navigation bar's height by using safeAreaInsetson the viewin the contained view controller:

您可以通过在包含的视图控制器中使用safeAreaInsets以编程方式获取导航栏的高度view

let navBarHeight = view.safeAreaInsets.top

This will account for whether it's a large title navigation bar or not, and whether or not there's a search bar attached to it.

这将说明它是否是一个大标题导航栏,以及是否有一个搜索栏附加到它上面。

See the safeAreaInsetsdocumentationfor more information.

有关更多信息,请参阅safeAreaInsets文档

回答by Andrew Bogaevskyi

You can simply get it in the next way (Swift 3):

您可以通过下一种方式(Swift 3)简单地获取它:

let barHeight = navigationController?.navigationBar.frame.maxY

To get correct value make sure that you call it after setting prefersLargeTitles

要获得正确的值,请确保在设置后调用它 prefersLargeTitles

navigationController?.navigationBar.prefersLargeTitles = false

回答by Harshal Valanda

There is no specification in Apple Docs

Apple Docs 中没有规范

Apple Docs

苹果文档

According to Geoff Hackworthits 88

根据Geoff Hackworth 的说法,它的 88

Navigation title types :

导航标题类型:

  • Standard title
  • Large title
  • 标准标题
  • 大标题

Increasing navigation bar in iOS 11

在 iOS 11 中增加导航栏

navigationController?.navigationBar.prefersLargeTitles = true

回答by Lance Samaria

If you're using a uiwindow and you need to know the top bar height you can use this:

如果您使用的是 uiwindow 并且需要知道顶部栏的高度,则可以使用以下命令:

guard let keyWindow = UIApplication.shared.keyWindow else { return }

let navBarHeight = keyWindow.safeAreaInsets.top

print("navBarHeight:" , navBarHeight)

I got the idea from @Paolo's answer

我从@Paolo 的回答中得到了这个想法

回答by Leonif

Use it if you want to know where need start content

如果您想知道需要从哪里开始内容,请使用它

extension UIViewController {
  var navigationBarbarContentStart: CGFloat {
    return self.navigationBarTopOffset + self.navigationBarHeight
  }
  var navigationBarTopOffset: CGFloat {
    return self.navigationController?.navigationBar.frame.origin.y ?? 0
  }

  var navigationBarHeight: CGFloat {
    return self.navigationController?.navigationBar.frame.height ?? 0
  }
}