It seems that when my app loads, it does not know its current orientation:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (o
for those who looking answer for Swift 3 or 4. just add that code inside of viewDidLoad() block.
let orientation = UIApplication.shared.statusBarOrientation
if orientation == .portrait {
// portrait
} else if orientation == .landscapeRight || orientation == .landscapeLeft{
// landscape
}
update for depreciation alerts for IOS 13 and Swift 5.x use code block below.
if #available(iOS 13.0, *) {
let orientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
if orientation == .portrait {
// portrait
} else if orientation == .landscapeRight || orientation == .landscapeLeft{
// landscape
}
} else {
// Fallback on earlier versions
let orientation = UIApplication.shared.statusBarOrientation
if orientation == .portrait {
// portrait
} else if orientation == .landscapeRight || orientation == .landscapeLeft{
// landscape
}
}