iOS6:supportedInterfaceOrientations不工作(被调用但接口仍然旋转) [英] iOS6: supportedInterfaceOrientations not working (is invoked but the interface still rotates)

查看:535
本文介绍了iOS6:supportedInterfaceOrientations不工作(被调用但接口仍然旋转)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有多个视图,一些视图需要同时支持纵向和横向,而其他视图只需要支持纵向。因此,在项目摘要中,我已经选择了所有方向。

In my app I have multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. Thus, in the project summary, I have all selected all orientations.

以下代码用于在iOS 6之前禁用给定视图控制器上的横向模式:

The below code worked to disable landscape mode on a given view controller prior to iOS 6:

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

由于在iOS6中不推荐使用shouldAutorotateToInterfaceOrientation,我将以上内容替换为:

Since shouldAutorotateToInterfaceOrientation was deprecated in iOS6 I've replaced the above with:

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMask.Portrait;
}

视图出现时正确调用此方法(我可以设置断点到确保这一点,但界面仍然旋转到横向模式,无论我只返回肖像模式的蒙版。我做错了什么?

This method is correctly called when the view appears (I can set a breakpoint to ensure this), but the interface still rotates to landscape mode regardless of the fact that I'm returning the mask for portrait modes only. What am I doing wrong?

目前似乎无法构建一个每个视图具有不同方向要求的应用程序。它似乎只遵循项目摘要中指定的方向。

It seems that it's currently impossible to build an app that has different orientation requirements per view. It seems to only adhere to the orientations specified in the project summary.

推荐答案

如果您使用 UINavigationController作为根窗口控制器,它将 shouldAutorotate & supportedInterfaceOrientations 将被调用。

If your are using a UINavigationController as the root window controller, it will be its shouldAutorotate & supportedInterfaceOrientations which would be called.

如果您使用的是 UITabBarController ,请注意等等。

Idem if you are using a UITabBarController, and so on.

所以要做的是将您的导航/标签栏控制器子类化并覆盖其 shouldAutorotate & supportedInterfaceOrientations methods。

So the thing to do is to subclass your navigation/tabbar controller and override its shouldAutorotate & supportedInterfaceOrientations methods.

这篇关于iOS6:supportedInterfaceOrientations不工作(被调用但接口仍然旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆