我有一个应用程序,我希望在某些 View 中支持设备旋转,但其他在横向模式下并不特别有意义,因此当我交换 View 时,我想强制将旋转设置为纵向。
UIDevice 上有一个未记录的属性 setter 可以解决问题,但显然会生成编译器警告,并且可能会在 SDK 的 future 版本中消失。
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
是否有任何记录在案的方法来强制定向?
更新:我想我会提供一个示例,因为我不是在寻找 shouldAutorotateToInterfaceOrientation,因为我已经实现了它。
我希望我的应用在 View 1 中支持横向和纵向,但在 View 2 中仅支持纵向。我已经为所有 View 实现了 shouldAutorotateToInterfaceOrientation 但如果用户在 View 1 中处于横向模式然后切换到 View 2,我想要强制手机旋转回纵向。
最佳答案
这是很久以后的事,但以防万一有人不使用导航 Controller 和/或不希望使用未记录的方法:
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
展示和关闭一个普通 View Controller 就足够了。
显然,您仍然需要在覆盖 shouldAutorotateToInterfaceOrientation 时确认或拒绝方向。但这会导致 shouldAutorotate... 被系统再次调用。
https://stackoverflow.com/questions/181780/