supportedInterfaceOrientations未使用iOS 7调用 [英] supportedInterfaceOrientations not called with iOS 7

查看:163
本文介绍了supportedInterfaceOrientations未使用iOS 7调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一个答案,但找不到任何解决我问题的方法。

I searched for an answer to this, but couldn't find anything which solved my problem.

所以这就是问题:
我有一个自定义UINavigationController,在创建它时,在rootViewController上调用 supportedInterfaceOrientations 方法(仅支持肖像)。
但是当把另一个ViewController推到堆栈上时,这个方法不会在推送的ViewController上调用(支持除了颠倒之外)。

So here's the problem: I have a custom UINavigationController, when creating it the supportedInterfaceOrientations method is called on the rootViewController(only supports portrait). But when pushing an other ViewController onto the stack this method isn't called on the pushed ViewController(supports all but upside-down).

我解决了它通过在 viewDidLoad -method中调用 [self supportedInterfaceOrientations] ,但我认为这不是解决问题的好方法。

I solved it by calling [self supportedInterfaceOrientations] in the viewDidLoad-method, but i think that's not a good way to solve the problem.

我希望你可以帮我解决这个问题。

I hope you can help me in that matter.

这是我在第二个viewController中实现的代码。

Here's my code i implemented in the second viewController.

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        [[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAllButUpsideDown];
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        [[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAll];
        return UIInterfaceOrientationMaskAll;
    }
}

我认为johnMa的解决方案应该可以正常工作大多数应用程序,但在我的情况下,我认为有一个特殊的问题,但我现在自己解决了(不确定它是否是一个好的,但它的工作原理)。

I think the solution from johnMa should work fine for the most apps, but in my case, there's a special problem i think, but i solved it by myself now(not sure if it's a good one, but it works).

我实现了 - (void)navigationController :( UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 我的navigationController-delegate上的方法。

I implemented the - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated method on my navigationController-delegate.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (DEF_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
        if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
            [viewController supportedInterfaceOrientations];
        }
    }
}

我希望这可以帮助别人具有相同的问题。

I hope this can help others with the same problem.

推荐答案

您应该在自定义NavigationController中实现这些代码。

You should implement these code in your custom NavigationController.

 - (NSUInteger)supportedInterfaceOrientations {
    if ([self.topViewController isMemberOfClass:[RootViewController class]]){
        return UIInterfaceOrientationMaskPortrait;
    }else{
        return UIInterfaceOrientationMaskAllButUpsideDown;
   }  
 }

因为当您的设备旋转时,它会询问您的应用rootController(Custom NavigationController)首先,如果 supportedInterfaceOrientations 没有在那里实现。那么它会向rootController询问 supportedInterfaceOrientations

because when your device rotate, it will ask your app rootController(Custom NavigationController) first, if supportedInterfaceOrientations is not implement there. then it will ask the rootController for supportedInterfaceOrientations.


一个视图控制器充当主窗口的根视图控制器或在主窗口上全屏显示可以声明它支持的方向。查看控制器编程指南

这篇关于supportedInterfaceOrientations未使用iOS 7调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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