P.J*_*P.J 14 iphone orientation uinavigationcontroller ios ios6
我正在使用此代码
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
[self presentViewController:navigationControllerCustom animated:YES completion:nil];
}
else
{
[self presentModalViewController:navigationControllerCustom animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序有两个方向纵向和纵向颠倒.此代码适用于iOS 5.1,但方向在iOS 6上不起作用
我也在navigationControllerCustom
课上添加了这段代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
提前致谢.
Dan*_*iel 25
您必须将此包含在您的应用程序委托中:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
还要确保View Controller都具有以下功能,对我来说工作正常.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
该文档还说,UINavigationController's
它不会查询其顶级View Controller支持的方向,尽管开发者论坛上的苹果工程师确实这么说......似乎它没有.因此,您应该添加一个类别UINavigationController
,这是我使用的类别:
#import "UINavigationController+autorotate.h"
@implementation UINavigationController (autorotate)
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
@end
Run Code Online (Sandbox Code Playgroud)
有关AutoRotate如何在iOS 6上运行的更多信息,请查看此答案