I use following code to see if the device is in landscape mode or not:
UIDevice.currentDevice().orientation.isLandscape.boolValue
It works
The isValidInterfaceOrientation
should be detected before checking the orientation isLandscape
. Don't process the flat message with isValidInterfaceOrientation == false
(when it has any value of isLandscape
).
I had a hazzel with this until I read the topic more carefully. With consideration of the isValidInterfaceOrientation
it works fine.
@objc func rotated() {
if (UIDevice.current.orientation.isValidInterfaceOrientation) {
if (UIDevice.current.orientation.isLandscape) {
if(!bLandscape) {
bLandscape = true
setupTabBar() // Repaint the app
}
} else { // Portait
if(bLandscape) {
bLandscape = false
setupTabBar() // Repaint the app
}
}
}
}