IOS 7获取错误的状态栏高度

时间:2015-05-05 04:07:04

标签: ios swift statusbar

我尝试在设备快速旋转时ios 7将获得错误的状态栏高度。我测试了IPad Air(ios 7.0)和IPhone 6(ios 8.2)。有没有可以获得正确状态栏高度的解决方案?

问题编码(得到self.view.bounds.size.width):

let status_height = UIApplication.sharedApplication().statusBarFrame.size.height

1 个答案:

答案 0 :(得分:7)

旋转时状态栏高度会改变,所以

选项1

首先检查statusBarOrientation

UIApplication.sharedApplication().statusBarOrientation.

肖像时使用此

let status_height = UIApplication.sharedApplication().statusBarFrame.size.height

横向时使用此

 let status_height = UIApplication.sharedApplication().statusBarFrame.size.width

选项2 将其转换为正确的坐标 在ViewController中,您希望获得高度

     var statusBarFrame = self.view.window?.convertRect(UIApplication.sharedApplication().statusBarFrame, fromView: self.view)
     var height = statusBarFrame?.height