presentViewController在iOS 6中不支持方向 [英] presentViewController not supporting orientation in iOS 6

查看:105
本文介绍了presentViewController在iOS 6中不支持方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
    {
        [self presentViewController:navigationControllerCustom animated:YES completion:nil];
    }
    else
    {
        [self presentModalViewController:navigationControllerCustom animated:YES];
    }

我的应用程序有两个方向Portrait和Portrait颠倒。此代码适用于iOS 5.1,但方向在iOS 6上不起作用

My application has two orientation Portrait and Portrait upside down. This code works well with iOS 5.1, but orientation does not work on iOS 6

我还在 navigationControllerCustom class

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

请帮我解决这个问题。

提前致谢。

推荐答案

您必须在申请代表中包含此内容:

You must include this in you application delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

还要确保View Controller的两者都有以下内容,对我来说很好。

Also make sure the View Controller's both have the following, works fine for me.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

文档还说 UINavigationController的不会查询其顶级View Controller以获得支持的方向,尽管开发者论坛上的Apple工程师确实这么说......似乎它没有。因此,您应该为 UINavigationController 添加一个类别,这是我使用的类别:

The documentation also says that UINavigationController's doesn't query its top View Controller for orientations supported, although an Apple engineer over on the Developer Forums did say so... it seems that it does not. Therefore you should add a category for UINavigationController, this is the one I use:

#import "UINavigationController+autorotate.h"

@implementation UINavigationController (autorotate)

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

@end

有关AutoRotate如何工作的详细信息在iOS 6上查看此答案

For more information how AutoRotate works on iOS 6 check out this answer

这篇关于presentViewController在iOS 6中不支持方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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