presentViewController 在 iOS 6 中不支持方向

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

问题描述

我正在使用此代码

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

我的应用程序有两个方向纵向和纵向倒置.此代码适用于 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 类中添加了这段代码

I have also added this code on my 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;
}

还要确保视图控制器都具有以下内容,对我来说可以正常工作.

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's 不会查询其顶部视图控制器以获取支持的方向,尽管开发者论坛上的苹果工程师确实这么说......似乎它没有.因此,您应该为 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 中不支持方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)