if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation) { print("landscape") } if UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation){ print("portrait") }
How can I check if it's landscape left or right?
LandscapeLeft: The device is in landscape mode, with the device held upright and the home button on the right side. LandscapeRight: The device is in landscape mode, with the device held upright and the home button on the left side. Add comment · Share.
Detecting Orientation Changes in Javascript Should you need to simply detect when a user changes orientation, you can use the following event listener: screen. orientation. addEventListener("change", function(e) { // Do something on change });
you can do something like,
if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft{ } else if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight{ } else if UIDevice.currentDevice().orientation == UIDeviceOrientation.UIDeviceOrientationPortraitUpsideDown{ } else if UIDevice.currentDevice().orientation == UIDeviceOrientation.UIDeviceOrientationPortrait{ }
SWIFT 5
if UIDevice.current.orientation.isLandscape { } else if UIDevice.current.orientation.isFlat { } else if UIDevice.current.orientation.isPortrait { } else if UIDevice.current.orientation.isValidInterfaceOrientation { }
SWIFT 3
if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft { } else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight { } else if UIDevice.current.orientation == UIDeviceOrientation.portrait { } else if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown { }
This works on Swift 3 & 4
switch UIApplication.shared.statusBarOrientation { case .portrait: //do something break case .portraitUpsideDown: //do something break case .landscapeLeft: //do something break case .landscapeRight: //do something break case .unknown: //default break }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With