iOS 6 - 某些视图的导航控制器横向旋转,而其他视图仅限 [英] iOS 6 - Navigation Controller Landscape Rotations For Some Views While Others Portrait Only
问题描述
我正在构建一个仅适用于主要视图的应用程序(正常和颠倒)。
我在项目设置/ Plist中设置了此设置,一切正常。
但是,我有一些模态视图可以显示图像/视频,我希望它们可以旋转到所有方向。
I am building an app that will be Portrait only for the main views (Both normal and upside down). I have set this setting in the Project Settings/Plist and all works fine. However, I have a few modal views that do things like display images/videos, and I want them to be able to rotate to ALL orientations.
I尝试为UINavigationController添加一个类别,但没有运气。
我还在viewController中添加了以下代码调用模态:
I tried adding a category for UINavigationController but no luck. I have also added to the viewController that calls the modal the below code:
-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
return NO;
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
return NO;
}
我已将以下代码添加到我希望允许所有的模态viewControllers中方向:
I have added the below code to the modal viewControllers that I want to allow all orientations:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
我缺少什么?有什么建议?
What am I missing? Any suggestions?
推荐答案
在iOS 6上,旋转处理已经改变。对于您描述的问题,有几种方法。首先,在plist中,启用除肖像上下颠倒的所有方向。
On iOS 6, rotation handling has changed. For the problem you described, there are several approaches. First, in the plist, enable all orientations except portrait upside down.
然后您可以使用以下解决方案之一:
Then you could use one of the following solutions:
- 使用UINavigationController的子类,它只允许旋转为纵向。
- 对于所有控制器,指定它们支持的旋转。
-
您可以覆盖应用程序委托中的方法。当方向更改或按下新视图控制器时,您的代理会调用该方法,您可以使用它暂时启用/禁用应用程序的横向显示:
- Use a subclass of UINavigationController that does only allow rotation to portrait.
- For all controllers specify which rotations they support.
You can override a method in your application delegate. As that method is called on your delegate whenever the orientation changes or a new view controller is pushed, you can use it to temporarily enable/disable landscape display for your app:
// In AppDelegate.h:
@property (nonatomic) BOOL portraitOnly;
// In AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return _portraitOnly ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskAllButUpsideDown;
}
// to switch to portrait only:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = YES;
// to switch to allowing landscape orientations:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = NO;
这篇关于iOS 6 - 某些视图的导航控制器横向旋转,而其他视图仅限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!