禁用纵向模式

时间:2011-12-22 09:11:10

标签: iphone objective-c ios ios4 landscape

我正在开发一个iPhone应用程序,该应用程序应该只在横向模式下工作。但是,当我旋转设备或模拟器时,viewContoller的模式从横向更改为纵向。我希望viewController在横向模式下维护,尽管设备或模拟器是纵向的。我怎么能做到这一点?提前谢谢。

4 个答案:

答案 0 :(得分:1)

在视图控制器中覆盖此方法:

// Override to allow orientations other than the default portrait orientation.
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientation, NO for other;
}

答案 1 :(得分:1)

将此添加到您的ViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);   
}

答案 2 :(得分:0)

更改info_plist .. 支持的界面方向仅设置横向

答案 3 :(得分:-1)

在所有ViewControllers中重写此方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

}

另见Only support for landscape Interface orientation

相关问题