presentViewController在iOS 6中不支持方向 [英] presentViewController not supporting orientation in 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 $ c上添加了此代码$ c> 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屋!