【发布时间】:2010-06-14 03:12:46
【问题描述】:
我用过这段代码,但它是私有 API,苹果也拒绝!
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
如果我在横向旋转我的设备然后打开我的应用程序,它将显示为纵向模式,我需要将我的设备旋转到另一个方向然后它会更新。
如何在调用 UIViewController 时将其更新为正确的方向?
【问题讨论】:
我用过这段代码,但它是私有 API,苹果也拒绝!
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
如果我在横向旋转我的设备然后打开我的应用程序,它将显示为纵向模式,我需要将我的设备旋转到另一个方向然后它会更新。
如何在调用 UIViewController 时将其更新为正确的方向?
【问题讨论】:
您应该在 UIViewController 类中使用以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
如果你需要在运行时更新方向,那么你必须返回其他常量
return (interfaceOrientation == UIInterfaceOrientationPortrait);
【讨论】: