简体   繁体   中英

ViewController from .xib file is loading in portrait mode and not in landscape mode in iOS

I have created a ViewController that I am calling from my my Main ViewController. I am able to successfully display the viewController, but my problem is that it is coming in Portrait mode, when in fact I have created it in Landscape mode. The viewController I am loading is created in a separate .xib file which I call from my main application. Here is the code I use to call it:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    NSLog(@"I was touched.");

    _nextView = [[NextLandscapeViewController alloc] initWithNibName:@"NextLandscapeViewController" bundle:nil];
    [_nextView setDelegate:(id)self];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_nextView];
    [self presentViewController:navigationController animated:YES completion:nil];

}

The thing that is confusing me is that I set the "Orientation" attribute for the view in the .xib file to Landscape in the "Attributes Inspector" in IB, yet it is still appearing in portrait mode. Why? Can anyone see what I'm doing wrong?

Thanks in advance to all who reply?

You may need to use the below methods in the NextLandscapeViewController

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

If the control doesn't reach these methods in View Controller, then you need to subclass the Navigation Controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM