What to use instead of UIScreen.mainScreen().applicationFrame for swift in ios 9.1?
Use
let rect1 = UIScreen.mainScreen().bounds // Returns CGRect
let rect2 = UIScreen.mainScreen().bounds.size // Returns CGSize
I know that UIScreen.mainScreen().bounds
is the recommended alternative; however, it's not the exact equivalent to UIScreen.mainScreen().applicationFrame
, particularly when your application does NOT occupy the whole screen, which happens with Split View and Slide Over feature on certain iPads.
In that case, this is a good alternative:
UIApplication.sharedApplication.keyWindow.frame
. (of course keyWindow
has to be available, that is, you did invoke makeKeyAndVisible
)
As of swift 3 you need to use it like this now.
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height