【问题标题】:ViewController from .xib file is loading in portrait mode and not in landscape mode in iOS.xib 文件中的 ViewController 以纵向模式加载,而不是在 iOS 中以横向模式加载
【发布时间】:2013-08-26 23:30:45
【问题描述】:

我创建了一个从我的主视图控制器调用的视图控制器。我能够成功显示 viewController,但我的问题是它是在纵向模式下出现的,而实际上我是在横向模式下创建它的。我正在加载的 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 文件中视图的“方向”属性设置为“横向”,但它仍然以纵向模式出现。为什么?谁能看到我做错了什么?

提前感谢所有回复的人?

【问题讨论】:

    标签: ios uiview uiviewcontroller uinavigationcontroller xib


    【解决方案1】:

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

    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    如果控件没有到达视图控制器中的这些方法,那么你需要子类化导航控制器。

    【讨论】:

    • 非常感谢您的及时回复。看起来我将不得不对我的导航控制器进行子类化。但是,我只使用单个视图应用程序,第二个视图控制器来自 .xib 文件。在这种情况下,我将如何子类化导航控制器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多