现在添加到我的 Storyboard 中的任何新 UIViewController
都需要有一个包含以下代码的类:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
在每个类上通过复制/粘贴来维护哪个很好,但这真的有必要吗?有没有更快的方法?
最佳答案
您可以使用 Supported interface orientations 键在 info.plist 文件中设置整个应用程序支持的界面方向(您也可以在项目摘要面板中以图形方式设置)。
如果这没有帮助(您在下面的评论中显然没有帮助),您可以将您的代码添加为 UIViewController 上的一个类别,从而使您不必将其复制并粘贴到每个 Controller 中。
如果这看起来有点激进,您可以改为创建一个包含该方法的 UIViewController 子类,并将其用作所有其他 Controller 的父类(super class)(BaseViewController 是一个好名字)。
关于ios - 对所有 UIViewControllers 使用相同的 UIInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8990490/