繁体   English   中英

来自.xib文件的ViewController在iOS中以纵向模式而不是横向模式加载

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

我已经创建了一个从主ViewController调用的ViewController。 我能够成功显示viewController,但是我的问题是它实际上是在Portrait模式下创建的,而实际上我是在Landscape模式下创建的。 我正在加载的viewController是在一个单独的.xib文件中创建的,我从主应用程序调用该文件。 这是我用来调用它的代码:

- (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];

}

令我感到困惑的是,我在IB的“属性检查器”中将.xib文件中视图的“方向”属性设置为“风景”,但它仍以纵向模式出现。 为什么? 谁能看到我在做什么错?

在此先感谢所有答复者?

您可能需要在NextLandscapeViewController中使用以下方法

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

如果控件未在View Controller中达到这些方法,则需要对Navigation Controller进行子类化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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