1

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.

enter image description here

Gautam Sareriya
  • 1,833
  • 19
  • 30

1 Answers1

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