iphone - 如何强制水平方向?

标签 iphone objective-c cocoa-touch uiviewcontroller

我想要执行以下操作:

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

不确定要设置什么才能实现这一点。

最佳答案

在每个 UIViewController 中,您需要重写 shouldAutorotateToInterfaceOrientation 方法,并为您支持的每个界面方向返回一个 bool 值:

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

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

有关更多信息,请查看 UIViewController class reference .

关于iphone - 如何强制水平方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538796/

相关文章:

iphone - 从 UIView 获取 UIViewController

ios - 当键是 NSNumber 时,我可以调用 nsdictionary 的 valueForKeyPath 吗?

objective-c - Objective-C 中如何将 double 值舍入为下一个整数值?

objective-c - 如何引用动态添加到 UITableView 的 UITextField?

iphone - 我需要添加 <UIAlertViewDelegate> 协议(protocol)吗?

iphone - 更改 UIScrollView 上的页面

iphone - CGAffineTransform重置

javascript - iPhone上的pageshow事件仅触发一次

iphone - 移除或重新激活 uivew 层上的 CABasicAnimation

ios - 触发 UIButton 操作时如何传递自定义对象?