我正在研究iOS 5的应用程序,我有一个需要在纵向视图中推送的控制器。从景观中将控制器推向纵向模式是相当棘手的,但最后我想出了如何做到这一点。我按presentModalViewController
或pushViewController
显示控制器,并在控制器内部覆盖preferredInterfaceOrientationForPresentation
metod。
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
它工作得很好只是它有一个问题。以下是情景。
我尝试通过调用[UIViewController attemptRotationToDeviceOrientation]
来修复它,但它没有帮助。
感谢您提前提供任何帮助。
答案 0 :(得分:1)
我希望你能得到一个更好的,有效的解决方案我做了一件令人讨厌的工作。我的问题是我需要支持从4.3到6.0。一些pushModal函数已经彻底改变,被弃用等等,旋转也有变化。
我写了一个RoatatingViewController,我已添加到root。我根据需要添加了push modals和pushviewconcollers。 当我需要弹出时,我会检查:如果堆栈上的所需组件处于所需的方向而不是好的方向,则无需更改。否则:弹出横向并推送portait实例并将横向数据复制到portait。
这不是很好,它不是内存效率高,而是在不崩溃所有iOS版本的情况下工作。祝你好运!
答案 1 :(得分:1)
您说使用IOS 5 ,但preferredInterfaceOrientationForPresentation()
方法仅从IOS 6 开始。
要解决您的问题(在ios5中),您需要覆盖shouldAutorotateToInterfaceOrientation()
方法,如下所示......
在目标视图控制器(在纵向模式下需要查看控制器),就像这样....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
<强>更新:强>
在当前视图控制器中(在横向模式下需要查看控制器),就像这样....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}