簡體   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