How can I request the current screen orientation of the iPhone / iPad?

I was curious to find out if there is a way to determine the screen orientation on the iPhone / iPad.

Currently, I find that I am setting a member variable when this message is called:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   self.orientation = interfaceOrientation;
   return YES;
}

... which feels something that I should be able to query as a state, and not track it when it changes.

+3
source share
3 answers

UIViewController has an interfaceOrientation property.

Do not confuse the orientation in a UIDevice, which is not an interface orientation, but a physical orientation.

+11
source

Use this if you have a status bar at the top.

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    // portrait             
} else {
    // landscape
}
+11
source

[[UIDevice currentDevice] orientation].

+1

Source: https://habr.com/ru/post/1748442/


All Articles