ios - 对所有 UIViewControllers 使用相同的 UIInterfaceOrientation

标签 ios uiviewcontroller uiinterfaceorientation

现在添加到我的 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/

相关文章:

ios - 在具有委托(delegate)的多个 UIViewController 队列上使用解雇 View Controller

ios - UIScrollView 没有显示在 UIViewController 上

ios - UIView 内部约束

ios - 我可以使用 iOS 应用程序在页面的墙上发帖吗?

ios - 更改 View Controller

ios - 如何在不将另一个 View Controller 插入堆栈的情况下支持 iOS 7 中的多个屏幕方向?

iOS:如何在 Storyboard中横向和纵向 View 之间切换?

iOS 8 : How to implement a rotating view controller on top of a portrait-only app?

iphone - 将图像存储和检索到 iphone 的 sqlite 数据库中

ios - 如何在swift中将sql时间戳转换为日期?