supportInterfaceOrientations更改时如何通知系统? [英] How do I notify system when supportedInterfaceOrientations changes?

查看:319
本文介绍了supportInterfaceOrientations更改时如何通知系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的根视图控制器的 supportedInterfaceOrientations 的实现几乎总是返回 UIInterfaceOrientationMaskAll ,但是有一个边缘情况会返回 UIInterfaceOrientationMaskLandscape



如果用户旋转设备,则此功能正常。但是,如果设备处于纵向模式,则不会调用 supportedInterfaceOrientations 方法,除非用户手动旋转设备。



如何以编程方式告诉系统此方法的返回值已更改?



根据文档,它似乎我应该能够调用 [UIViewController attemptRotationToDeviceOrientation] 然而这没有任何影响( supportedInterfaceOrientations 永远不会被调用并且屏幕不会旋转。)



我找到了其他人发布的各种解决方法来尝试解决这个问题,但是我的测试中没有一个可以工作。我怀疑他们可能在iOS 5.0中工作,但不是iOS 6.0。



我在根目录中返回 YES 查看控制器的 shouldAutorotate 方法。

解决方案

首先,它可能是如果你想在横向模式下呈现你的UIViewController,你会有用。

   - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{
返回UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

此外,很大程度上取决于你的UIViewController嵌入哪个控制器。 / p>

例如,如果它在UINavigationController中,那么你可能需要将UINavigationController子类化为覆盖这样的方向方法。



子类化UINavigationController(层次结构的顶层viewcontroller将控制方向。)需要将其设置为self.window.rootViewController。

   - (BOOL)shouldAutorotate 
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
返回self.topViewController.supportedInterfaceOrientations;
}

从iOS 6开始,UINavigationController不会询问其UIVIewControllers定向支持。因此我们需要对其进行子类化。



注意:



shouldAutorotate supportedInterfaceOrientations 方法总是在完成Push操作时调用UINavigationController。


My root view controller's implementation of supportedInterfaceOrientations almost always returns UIInterfaceOrientationMaskAll, however there is one edge case where it returns UIInterfaceOrientationMaskLandscape.

This is working, if the user rotates the device. However if the device is being held in portrait mode the supportedInterfaceOrientations method does not ever get called, unless the user manually rotates the device.

How can I programatically tell the system that the return value of this method has changed?

According to the documentation, it seems like I should be able to call [UIViewController attemptRotationToDeviceOrientation] however this does not have any effect (supportedInterfaceOrientations is never called and the screen does not rotate).

I found various workarounds others have posted to try and solve this problem, but none of them work in my tests. I suspect they may have worked in iOS 5.0, but not iOS 6.0.

I am returning YES in the root view controller's shouldAutorotate method.

解决方案

First of all, it might be useful if you used this if you want to present your UIViewController in Landscape mode.

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

Also, A lot depends on with which controller is your UIViewController embedded in.

Eg, If its inside UINavigationController, then you might need to subclass that UINavigationController to override orientation methods like this.

subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) needs to be set it as self.window.rootViewController.

- (BOOL)shouldAutorotate
 {
     return self.topViewController.shouldAutorotate;
 }
 - (NSUInteger)supportedInterfaceOrientations
 {
     return self.topViewController.supportedInterfaceOrientations;
 }

From iOS 6, it is given that UINavigationController won't ask its UIVIewControllers for orientation support. Hence we would need to subclass it.

Note :

The shouldAutorotate and supportedInterfaceOrientations method always get called for UINavigationController whenever Push operations are done.

这篇关于supportInterfaceOrientations更改时如何通知系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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