如何在 iOS 6 中强制 UIViewController 为纵向 [英] How to force a UIViewController to Portrait orientation in iOS 6

查看:22
本文介绍了如何在 iOS 6 中强制 UIViewController 为纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 ShouldAutorotateToInterfaceOrientation 在 iOS 6 中被弃用,我用它来强制特定视图仅纵向,在 iOS 6 中执行此操作的正确方法是什么?这仅适用于我应用的一个区域,所有其他视图都可以旋转.

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 and I used that to force a particular view to portrait only, what is the correct way to do this in iOS 6? This is only for one area of my app, all other views can rotate.

推荐答案

如果你想让我们所有的导航控制器都尊重顶视图控制器,你可以使用一个类别,这样你就不必经历和改变一堆类名.

If you want all of our navigation controllers to respect the top view controller you can use a category so you don't have to go through and change a bunch of class names.

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

正如一些评论指出的那样,这是解决问题的快速方法.更好的解决方案是子类 UINavigationController 并将这些方法放在那里.子类也有助于支持 6 和 7.

As a few of the comments point to, this is a quick fix to the problem. A better solution is subclass UINavigationController and put these methods there. A subclass also helps for supporting 6 and 7.

这篇关于如何在 iOS 6 中强制 UIViewController 为纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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