Rotation on certain screens

Asked

Viewed 619 times

4

How do I define only one UIViewController be able to rotate?

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 one should be enabled the ways in landscape.

Note: Currently the settings of my project is to accept only the mode portrait.

  • Do you want this to support all guidelines or just "landscape"?

  • All guidelines

3 answers

1

Do the following:

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

You will get the Tab Bar Controller and two related views being: FirstViewController and the SecondViewController

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

inserir a descrição da imagem aqui

That’s it! It works : just the FirstView is with Orientation fixed. A SecondView allows the change of orientation by adjusting the new dimensions.

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

0

  1. Enable in the project settings all the guidelines you will need. (In your case enables everything, I understand.)
  2. In all UIViewController's of your project implement the method supportedInterfaceOrientations returning the desired configuration.

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

  3. If you’re using Storyboard leave it all marked as inferred in Simulated Metrics

-2

Hello, on Appdelegate. h add

@property (nonatomic , assign) bool blockRotation;

and in Appdelegate. m

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

And in the views you want to disable the 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 each view to 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.