Rotation on certain screens

How do I set only one UIViewController to be enabled in rotation?

The scenario is as follows:

I own 5 screens, and in all of them I must enable only the mode portrait. But I have a sixth screen, and this should be enabled the modes in landscape.

Note: Currently my project settings are to accept only portrait mode.

Author: Gian, 2014-12-16

3 answers

Do the following:

Create a project in Xcode 6.1.1 with template Tabbed Application because it is faster to develop and demonstrate the functionality. I did in Swift but it should be equal in Objective-C

You will have Tab Bar Controller and two related views being: FirstViewController and a SecondViewController

In one of the views (FirstViewController for example) do as in the figure below. The other leave everything in Default (Orientation: inferred, etc.). For min only the fixed portrait orientation in view FirstView Worked when I unchecked the option Resize view from NIB.

insert the description of the image here

That's it ! Works: only FirstView gets fixed orientation. The SecondView allows the change of orientation to suit the new dimensions.

You can download the project at https://github.com/joao-parana/only-one-can-landscape .

 1
Author: João Paraná, 2014-12-21 23:59:54
  1. Enable in the project settings all the guidelines you will need. (In your case it enables everything, as I understand it.)
  2. In all UIViewController's of your project implement the supportedInterfaceOrientations method by returning the desired configuration.

    Example in controller that will support all returns UIInterfaceOrientationMaskAll in the others returns UIInterfaceOrientationMaskPortrait

  3. if you are using Storyboard leave everything marked as inferred in Simulated Metrics
 0
Author: Otávio, 2015-05-15 08:43:21

Hello, no AppDelegate.H add

@property (nonatomic , assign) bool blockRotation;

And no AppDelegate.m

-(NSUInteger)application:(UIApplication *)application       supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.blockRotation) {
    return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAll;
}

And in the views you want to disable rotation, just add

- (void)viewDidLoad
{
 [super viewDidLoad];
    AppDelegate* shared=[UIApplication sharedApplication].delegate;
    shared.allowRotation=YES;
}

-(void)viewWillDisappear:(BOOL)animated{
  AppDelegate* shared=[UIApplication sharedApplication].delegate;
  shared.allowRotation=NO;

  }

Another way is to add in each view the check

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait)
        return YES;

    return NO;
}

Source: https://stackoverflow.com/questions/5296399/ios-how-to-stop-view-rotate

 -2
Author: PauloHDSousa, 2017-05-23 12:37:29