iOS 6 - 某些视图的导航控制器横向旋转,而其他视图仅纵向 [英] iOS 6 - Navigation Controller Landscape Rotations For Some Views While Others Portrait Only

查看:31
本文介绍了iOS 6 - 某些视图的导航控制器横向旋转,而其他视图仅纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个仅适用于主要视图(正常和倒置)的纵向应用程序.我已经在项目设置/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.

我尝试为 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;
}

我已将以下代码添加到我希望允许所有方向的模态视图控制器中:

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:

  1. 使用 UINavigationController 的子类,它只允许旋转到纵向.
  2. 为所有控制器指定它们支持的旋转.
  3. 您可以覆盖应用程序委托中的方法.由于每当方向更改或推送新的视图控制器时都会在您的委托上调用该方法,您可以使用它来临时启用/禁用应用程序的横向显示:

  1. Use a subclass of UINavigationController that does only allow rotation to portrait.
  2. For all controllers specify which rotations they support.
  3. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆