如何强制水平方向? [英] How to force horizontal orientation?

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

问题描述

我想要执行以下操作:

ViewControllerA不应该进入水平方向
ViewControllerA推动ViewControllerB
ViewControllerB应该进入水平方向。

ViewControllerA should not go into horizontal orientation ViewControllerA pushes ViewControllerB ViewControllerB should go into horizontal orientation.

不确定要执行哪些操作。

Not sure what to set to make this happen.

推荐答案

在每个 UIViewController 中,您需要重写 shouldAutorotateToInterfaceOrientation 方法,并为您支持的每个接口方向返回一个布尔值:

In each UIViewController, you'll need to override the shouldAutorotateToInterfaceOrientation method and return a boolean value for each interface orientation you support:

// ViewControllerA
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

// ViewControllerB
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

有关更多信息,请查看 UIViewController 类别参考

For more information, check out the UIViewController class reference.

这篇关于如何强制水平方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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