Auto rotate support for view added via presentModalViewController?

It seems that no matter what orientation I support in my views in my application, when I show the view using currentModalViewController, the application binds to the portrait view. How can I support different orientations using a modal controller?

+3
source share
3 answers

The controller that you present with presentModalViewController: animated: should support any orientation, usually using this method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

, , .

+1

. TRUE AutorotateInterfaceOrientation, , . ( ), . ! , , . , , viewDidLoad, . presentModalView , viewDidLoad (, ). , - :

- (void) viewDidLoad
{
    [super viewDidLoad];
    // add this line
    [self performSelector:@selector(presentModal) withObject:nil afterDelay:0];
}

-(void) presentModal{
    // here present your view
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

0

I just solved this problem for myself by adding code to viewDidAppear. I think the reason that it didn’t show the correct orientation for me was because I had a modal show code in viewDidLoad, and at that moment I think the view just loaded, but the orientation has not been set yet . So, adding it to viewDidAppear, I worked for me. You are probably also lucky in viewWillAppear (because by then it should know what orientation, borders, dimensions, etc.).

0
source

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


All Articles