Why [UIApplication sharedApplication] .statusBarOrientation returns invalid values

Hi in my application, I would like to know the value of statusbarorientation . For this, I use the [UIApplication sharedApplication].statusBarOrientation . In fact, this method should return 4 for landscape and 2 for sweat mode. But this method returns values ​​in the opposite way. Tools for landscape 2 and for potrait 4. Please let me know how to fix this problem. In the supportedInterfaceOrientations method, I use return UIInterfaceOrientationMaskAll;

Please help me in solving this problem.

+4
source share
1 answer

This is likely because UIDeviceOrientationLandscapeRight is assigned to UIInterfaceOrientationLandscapeLeft and UIDeviceOrientationLandscapeLeft is assigned to UIInterfaceOrientationLandscapeRight.

The reason for this is that rotating the device requires rotating the contents in the opposite direction.

Starting with iOS 8, you should use the UITraitCollection and UITraitEnvironment APIs, as well as the size class properties used in these APIs, instead of using UIInterfaceOrientation constants or otherwise writing the application in terms of interface orientation.

Anyway, orientation in this way worked for me.

 var orientation = UIApplication.SharedApplication.StatusBarOrientation; switch (orientation) { case UIInterfaceOrientation.PortraitUpsideDown: // The device is in portrait mode but upside down, with the device held upright and the home button at the top. case UIInterfaceOrientation.Portrait: // The device is in portrait mode, with the device held upright and the home button on the bottom. case UIInterfaceOrientation.LandscapeLeft: // The device is in landscape mode, with the device held upright and the home button on the left side. case UIInterfaceOrientation.LandscapeRight: // The device is in landscape mode, with the device held upright and the home button on the right side. case UIInterfaceOrientation.Unknown // The orientation of the device cannot be determined. } 

We also consider that

If your application has rotatable content, you should not arbitrarily set the state-bar orientation using this method. The frame-state orientation set by this method does not change if the device orientation changes.

+1
source

All Articles