问题描述
我正在使用此代码
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 中不支持方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!