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

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

问题描述

由于iOS 6中不推荐使用 ShouldAutorotateToInterfaceOrientation 而我用它来强制特定视图仅限肖像,这是什么方法在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天全站免登陆