Orientation issue in ios 6

I work in a generic application that works fine up to ios 5, but ios 6 has an orientation problem. My application works only in portrait mode. The problem is that my ipad is in landscape mode, and if I start my application, the orientation will not change to protrait. So please help me with some code so that I make my application be in protrait mode only regardless of device orientation before starting the application

0
source share
3 answers

This is because Apple has changed the way it controls the orientation of the UIViewController. In iOS6, Oreintation is handled differently. In iOS6 containers (e.g. UINavigationController) do not consult their children to determine if they should autorotate. By default, UIInterfaceOrientationMaskAll interface orientations for iPad idioms and UIInterfaceOrientationMaskAllButUpsideDown for iPhone idioms are supported for applications and view controllers. This change in device orientation has changed by default.

So, you need to follow some steps.

1 -Set the orientation from here

enter image description here

2 -Put this code in the FirstViewController added to the RootViewController

@implementation UINavigationController (RotationIn_IOS6) //Here UINavigationController is the RootViewController added To the Window -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end 

** Put below methods in ViewController introduced in IOS6 Allow Oreintation change **

  - (BOOL)shouldAutorotate { return NO; } /*Return the Number of Oreintation going to supported in device*/ - (NSUInteger)supportedInterfaceOrientations { return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown ); } // Returns interface orientation masks. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown ) ; } 
+2
source

First we need to set the supported orientations to Targets-> Summary ...

On iOS6.0, the shouldAutorotateToInterfaceOrientation Method has been deprecated. Therefore, instead of this method, we should use the toAutorotate method.

And with the supportedInterfaceOrientations method, we need to set what orientations we want, as UIInterfaceOrientationMaskAll, if we want all orientations

+4
source

In your ViewController.m you will need to define your supported orientation. In iOS 6, this is a method that handles the supported orientation.

 - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll; } 

UIInterfaceOrientationMaskAll means that it will support all view orientation.

Also read the Apple Doc about Orientation

0
source

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


All Articles