[英]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.