iOS11 iPhoneX 模拟器中的导航栏未显示到顶部边缘

Navigation bar not showing to the top edge in iOS11 iPhoneX simulator

我遇到了这个问题,过去几天我找不到答案。

在 iOS 11 模拟器中,导航栏没有显示在 iPhone X 的顶部边缘,这是模拟器错误还是我做错了什么?

身高88

身高145

没有背景图片

这是我在 appdelegate 中的代码

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
UIImage *navImage = [[UIImage imageNamed:@"iPhone-Navigationbar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UINavigationBar appearance] setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];

奇怪的行为,一些想法:

  • 您试过删除背景图片吗?
  • 背景图片有多大? iPhone X 导航栏更高 (145pt)。