简体   繁体   English

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

[英]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. 我已经创建了一个从主ViewController调用的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. 我能够成功显示viewController,但是我的问题是它实际上是在Portrait模式下创建的,而实际上我是在Landscape模式下创建的。 The viewController I am loading is created in a separate .xib file which I call from my main application. 我正在加载的viewController是在一个单独的.xib文件中创建的,我从主应用程序调用该文件。 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. 令我感到困惑的是,我在IB的“属性检查器”中将.xib文件中视图的“方向”属性设置为“风景”,但它仍以纵向模式出现。 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 您可能需要在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. 如果控件未在View Controller中达到这些方法,则需要对Navigation Controller进行子类化。

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

相关问题 iOS纵向和横向模式 - ios portrait and landscape mode 如何在iOS中将人像之类的ViewView模式更改为横向模式? - How to change One ViewController mode like Portrait to landscape in iOS? 纵向模式下的第一个ViewController和横向模式下的SecondViewController - 1st ViewController in Portrait and SecondViewController in Landscape Mode 从B VIewcontroller(固定肖像)返回A,A不会自动旋转到风景模式(设备处于风景模式) - return back from B VIewcontroller(Fixed Portrait), to A , A is not rotating to landscape mode automatically(Device is in Landscape Mode) iOS7:从横向模式加载子视图控制器时,查看会说话的肖像帧 - iOS7 : View talking portrait frame when loading child view controller from landscape mode iOS:从LandScape ViewController切换到Portrait ViewController - iOS: Switching to Portrait ViewController from LandScape ViewController IOS设备方向卡在纵向模式下,没有横向 - IOS Device Orientation Stuck at Portrait mode, no Landscape 在纵向模式下,尴尬的横向键盘,IOS 8 - Awkward Landscape keyboard in portrait mode, IOS 8 纵向模式下的动画UIView在ios的横向上不一致 - animated UIView in portrait mode is not consistent in landscape on ios 用于纵向和横向模式iOS的自定义界面 - Custom interfaces for Portrait & Landscape mode iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM