Fab
Fab

Reputation: 836

Check the app orientation in iOS (not the device orientation)

Until now, I used to use this code to check if my device is in a portrait or landscape mode:

if (UIDeviceOrientationIsPortrait(UIDevice.current.orientation)){
           //portrait

}else {
          //landscape        
}

But I discovered that this variable check the real position of the device in the 3D space. So if my iPad or iPhone is in a portrait mode and I put it on a table, parallel to the ground, the orientation will not be considered as portrait. Is there a variable or something similar that can I check to know the orientation of the app and not the physical orientation?

Upvotes: 0

Views: 49

Answers (1)

Gereon
Gereon

Reputation: 17844

Use UIApplication.shared.statusBarOrientation: The current orientation of the app's status bar.

Upvotes: 1

Related Questions