I want to know the iPhone is currently in Portrait mode or in Landscape mode. If I forcefully do the "Portrait orientation mode" is on then there is way to know programmatically.
Asked
Active
Viewed 253 times
1
-
Is this the thing you need? https://stackoverflow.com/a/38894646/3940673 – Nikola Markovic Nov 05 '19 at 07:28
-
I got the correct answer from https://stackoverflow.com/questions/49164302/get-current-ios-device-orientation-even-if-devices-orientation-locked. – Gautam Sareriya Nov 05 '19 at 10:16
1 Answers
0
You can simply use orientation
to get the current device's orientation,
UIDevice.currentDevice().orientation
To check for portrait mode, you can simply do,
if UIDevice.currentDevice().orientation == .portrait {
//add your code here...
}
These can be the possible orientation
values,
public enum UIDeviceOrientation : Int {
case unknown
case portrait // Device oriented vertically, home button on the bottom
case portraitUpsideDown // Device oriented vertically, home button on the top
case landscapeLeft // Device oriented horizontally, home button on the right
case landscapeRight // Device oriented horizontally, home button on the left
case faceUp // Device oriented flat, face up
case faceDown // Device oriented flat, face down
}

PGDev
- 23,751
- 6
- 34
- 88