对所有 UIViewController 使用相同的 UIInterfaceOrientation
现在添加到我的故事板中的任何新 UIViewController
都需要有一个包含以下代码的类:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
通过在每个类上复制/粘贴来维护很好,但这真的有必要吗?难道就没有更快的方法吗?
Right now any new UIViewController
added to my storyboard needs to have a class that has the following code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Which is fine to maintain via copy/paste on each class, but is that really necessary? Is there not a faster way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用支持的界面方向键在 info.plist 文件中设置整个应用程序支持的界面方向(您也可以在项目摘要面板中以图形方式设置)。
如果这没有帮助(从下面的评论来看显然没有帮助),您可以将代码添加为 UIViewController 上的类别,从而使您不必将其复制并粘贴到每个控制器中。
如果这看起来有点激进,您可以创建一个包含该方法的 UIViewController 子类,并将其用作所有其他控制器的超类(BaseViewController 是一个很好的名称)。
You can set the supported interface orientations across the whole app in the info.plist file using the Supported interface orientations key (you can also set this graphically in the project summary panel).
If that doesn't help (which it apparently doesn't from your comment below) you could add your code as a category on UIViewController, thereby saving you from having to copy and paste it into every controller.
If that seems a bit radical, you could instead create a UIViewController subclass containing that method and use it as the superclass for all of your other controllers (BaseViewController would be a good name for it).