.xib文件中的ViewController在iOS中以纵向模式而不是横向模式加载
我已经创建了一个从主ViewController调用的ViewController。我能够成功地显示viewController,但我的问题是它是在纵向模式下出现的,而实际上我是在横向模式下创建的。我正在加载的viewController是在一个单独的.xib文件中创建的,我从主应用程序调用该文件。下面是我用来称呼它的代码:.xib文件中的ViewController在iOS中以纵向模式而不是横向模式加载,ios,uiview,uiviewcontroller,uinavigationcontroller,xib,Ios,Uiview,Uiviewcontroller,Uinavigationcontroller,Xib,我已经创建了一个从主ViewController调用的ViewController。我能够成功地显示viewController,但我的问题是它是在纵向模式下出现的,而实际上我是在横向模式下创建的。我正在加载的viewController是在一个单独的.xib文件中创建的,我从主应用程序调用该文件。下面是我用来称呼它的代码: - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"I was
- (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;
}
如果控件未到达视图控制器中的这些方法,则需要对导航控制器进行子类化。您可能需要在NextLandscapeViewController中使用以下方法
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
如果控件未到达视图控制器中的这些方法,则需要对导航控制器进行子类化。非常感谢您的及时回复。看起来我必须对导航控制器进行子类化。但是,我只使用单个视图应用程序,第二个视图控制器来自.xib文件。在这种情况下,我将如何子类化导航控制器?非常感谢您的及时回复。看起来我必须对导航控制器进行子类化。但是,我只使用单个视图应用程序,第二个视图控制器来自.xib文件。在这种情况下,我将如何子类化导航控制器?