0
votes

I try that the ios 7 will get the wrong height of status bar when the device rotated in swift. I have tested IPad Air (ios 7.0) and IPhone 6 (ios 8.2). It there any solution that can get the correct height of status bar?

Problem Coding(which it get self.view.bounds.size.width):

let status_height = UIApplication.sharedApplication().statusBarFrame.size.height
1
So,what you got from this code and why you say that is wrongLeo
it get the size of self.view.bounds.size.width from status_height when i rotate the device. status bar should not big as 1024.Jacky Shek
You need to update the status_height = UIApplication.sharedApplication().statusBarFrame.size.height after the rotation was made :)Bejibun

1 Answers

7
votes

The status bar height will change when rotate,So

Option 1

check statusBarOrientationfirst

UIApplication.sharedApplication().statusBarOrientation.

When in portrait Use this

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

When in landscape Use this

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

Option 2 Converted it to the right coordinate In the ViewController you want to get height

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