3

我正在开发一个代码,其中初始视图控制器是landscape视图。当按下该视图控制器中的按钮时,下一个视图控制器应该是portrait. 我root view controller的是一个navigation controller

这是一个故事板应用程序。

UIInterfaceOrientationLandscapeRight我在第一个根视图控制器和 UIInterfaceOrientationPortrait第二个视图控制器中返回了 Yes 。但旋转起初不起作用。我们必须旋转视图以将其更改为正确的旋转。

我该如何解决这个问题?

4

2 回答 2

3

这里改变设备方向的一种方法是......

-(void)viewWillAppear:(BOOL)animated
{
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

}

在这里你想在哪个类中改变方向然后在你的viewWillAppear:方法中写下这一行

并且为了删除 UIDevice 的警告,只需在你的 .m 文件中声明下面的代码

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end

这里代码在@implementation 文件上方定义,希望对您有所帮助...

:)

于 2012-09-17T06:40:41.460 回答
0

当您的第二个ViewController被加载时,在viewDidLoad或方向更改事件接收方法中添加此行:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

编辑:

好的,然后在要纵向显示的 CiewController 中更新您的方法shouldAutorotateToInterfaceOrientation,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

还要确保在 nib 文件中,您Portrait在属性检查器中设置了方向。

它会为你完成这项工作。

于 2012-09-17T06:39:52.357 回答