Michel
Michel

Reputation: 11753

A UIInterfaceOrientation issue

I want my iPhone app to globally behave as if only the UIInterfaceOrientationPortrait was permitted. But at the same time I want it to be aware of the physical orientation in order to react in a specific way, only within a limited area of the display. How can I get this?

I did some tests using the self.interfaceOrientation iVar of the UIViewController, but that does not seem to work, because this variable does not change.

Upvotes: 1

Views: 77

Answers (1)

rob mayoff
rob mayoff

Reputation: 385500

First, do [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]. Then register for UIDeviceOrientationDidChangeNotification. When you receive the notification, check [UIDevice currentDevice].orientation for the device's physical orientation.

You should definitely read the documentation for these APIs, because it contains some important warnings.

Also note that device orientation is returned as a UIDeviceOrientation, which is different than a UIInterfaceOrientation. Keep in mind this information from the UIInterfaceOrientation documentation:

You use these constants in the statusBarOrientation property and the setStatusBarOrientation:animated: method. Notice that UIDeviceOrientationLandscapeRight is assigned to UIInterfaceOrientationLandscapeLeft and UIDeviceOrientationLandscapeLeft is assigned to UIInterfaceOrientationLandscapeRight; the reason for this is that rotating the device requires rotating the content in the opposite direction.

Upvotes: 1

Related Questions