iPhone X status bar height

旧城冷巷雨未停 提交于 2019-12-05 15:57:14

问题


I have developed an app without autoLayout or interface-builder, all by code. It runs ok in all iPhones except iPhone X where the top bar stays under the new black thing in the middle.

It's possible to get that height by code, so I can shift my Navigationbar that height down and all runs normal ?

The solutions I see, they use auto layout.

I just want the get the distance to shift it down..


回答1:


In my Swift app, I get the frame of the status bar with

Swift: UIApplication.shared.statusBarFrame

Objective-C: [UIApplication sharedApplication].statusBarFrame

That's a CGRect, so you can get its height by doing size.height on that. So, altogether, you can do this in Objective-C:

[UIApplication sharedApplication].statusBarFrame.size.height



回答2:


You can always get the status bar height with or without status bar hidden by:

UIApplication.shared.keyWindow!.safeAreaInsets.top

and the home screen indicator

UIApplication.shared.keyWindow!.safeAreaInsets.bottom

If it's landscape the value would change

and safeAreaLayoutGuide is there also



来源:https://stackoverflow.com/questions/46775477/iphone-x-status-bar-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!