【发布时间】:2011-12-22 09:11:09
【问题描述】:
我正在开发一个 iPhone 应用程序,该应用程序只能在横向模式下工作。但是,当我旋转设备或模拟器时,viewContoller 的模式会从横向变为纵向。我希望 viewController 保持横向模式,尽管设备或模拟器是纵向的。我怎么能做到这一点?提前致谢。
【问题讨论】:
标签: iphone objective-c ios ios4 landscape
我正在开发一个 iPhone 应用程序,该应用程序只能在横向模式下工作。但是,当我旋转设备或模拟器时,viewContoller 的模式会从横向变为纵向。我希望 viewController 保持横向模式,尽管设备或模拟器是纵向的。我怎么能做到这一点?提前致谢。
【问题讨论】:
标签: iphone objective-c ios ios4 landscape
在您的视图控制器中覆盖此方法:
// Override to allow orientations other than the default portrait orientation.
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientation, NO for other;
}
【讨论】:
将此添加到您的ViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
【讨论】:
更改 info_plist .. 支持的界面方向仅设置横向
【讨论】:
在你所有的 ViewController 中重写这个方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
【讨论】: