强制风景iOS 6 [英] Force Landscape iOS 6

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

问题描述

我希望在我的应用中使一个视图横向.我设法使视图在手动旋转时保持在横向,但如果设备已经是纵向,则无论其支持的方向如何(使用 supportedInterfaceOrientations 方法设置),它都将保持纵向.有没有一种方法可以使视图自动旋转?我已经尝试过:

I am looking to have one view in my app have landscape orientation. I have managed to get the view to stay in landscape when rotated manually, but if the device is already portrait, it stays portrait, regardless of its supported orientation (set using supportedInterfaceOrientations method) . Is there a way to get the view to rotate automatically? I have tried:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

但这是行不通的.

任何建议将不胜感激!

推荐答案

一种方法是通过覆盖 preferredInterfaceOrientationForPresentation ,但是要调用该方法,必须(如模式),并且没有按此处:

One way to do this is by overriding preferredInterfaceOrientationForPresentation but in order for that to be called the viewController has to be presented (as in modal) and not pushed as mentioned here:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    NSLog(@" preferred called");
    return UIInterfaceOrientationPortrait;
}

要在UINavigationController中显示viewController,请使用:

In order to present your viewController in a UINavigationController use:

UINavigationController *presentedNavController = [[UINavigationController alloc] initWithRootViewController:protraitViewController];

[self presentViewController:presentedNavController animated:YES completion:nil];

要使UINavigationController尊重您当前的viewController的方向首选项,请使用此简单的类别而不是子类.

To make UINavigationController respect your current viewController's orientation preferences use this simple category instead of sub-classing.

此外,此部分该文档是更好地了解iOS方向处理的好读物.

Also, this part of Apple's documentation is a good read for understanding iOS orientation handling better.

这篇关于强制风景iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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