我正在开发一个代码,其中初始 View Controller 是 landscape
View 。当按下该 View Controller 中的按钮时,下一个 View Controller 应该是 portrait
。我的 root view controller
是一个 navigation controller
。
这是一个 Storyboard应用程序。
我在第一个 Root View Controller 中为 UIInterfaceOrientationLandscapeRight
返回了 Yes 并且
UIInterfaceOrientationPortrait
用于第二个 View Controller 。但是旋转一开始不起作用。我们必须旋转 View 以将其更改为正确的旋转。
我该如何解决这个问题?
最佳答案
这里改变设备方向的一种方法是......
-(void)viewWillAppear:(BOOL)animated
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
在这里你想在哪个类中改变方向然后在你的viewWillAppear:
方法中写下这行
并且为了移除 UIDevice 的警告,只需在您的 .m 文件中声明以下代码
@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end
此处代码定义在@implementation 文件之上 希望这对你有帮助...
:)
关于iphone - 界面方向旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12454137/