iPhone(iOS 5)强制从横向绘制肖像并返回
我正在为iOS5开发应用程序,我有一个控制器需要在纵向视图中推送。从横向角度在纵向模式下推动控制器是相当棘手的,但我终于想出了方法。我通过iPhone(iOS 5)强制从横向绘制肖像并返回,iphone,objective-c,cocoa-touch,ios5,landscape-portrait,Iphone,Objective C,Cocoa Touch,Ios5,Landscape Portrait,我正在为iOS5开发应用程序,我有一个控制器需要在纵向视图中推送。从横向角度在纵向模式下推动控制器是相当棘手的,但我终于想出了方法。我通过presentModalViewController或pushViewController显示控制器,并在控制器内部覆盖preferredinterfacedirectionforpresentationmetod -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
presentModalViewController
或pushViewController
显示控制器,并在控制器内部覆盖preferredinterfacedirectionforpresentation
metod
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
它工作正常,只是有一个问题。下面是场景
[UIViewController attemptRotationToDeviceOrientation]
来修复它,但没有任何帮助
提前感谢您的帮助。我希望您能得到一个更好的、有效的解决方案。我做了一件很糟糕的事情来工作。我的问题是我需要从4.3支持到6.0。一些模态函数发生了根本性的变化,变得不推荐使用,等等,旋转时也有变化 我编写了一个RoatatingViewController,并将其添加到根目录中。然后,我根据需要添加了push modals和pushviewconcoller。 当我需要弹出时,我会做一个检查:如果堆栈上所需的组件处于所需的方向,则不会发生任何更改。否则:弹出横向并推送portait实例,然后将横向数据复制到portait
它不好,内存效率不高,但在所有iOS版本中都能正常工作。祝你好运 您的说法是使用IOS 5,但
更喜欢InterfaceOrientationforPresentation()
方法仅适用于IOS 6以后的版本
要解决您的问题(在ios5中),您需要覆盖shouldAutorotateToInterfaceOrientation()
方法,如下所示
在目标视图控制器中(纵向模式下需要的视图控制器)如下所示
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
更新:
在当前视图控制器中(在横向模式下需要的视图控制器)如下所示
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
谢谢你的回答,巴努,我已经看过好几次了,但它从来没有帮助我强迫一些控制器在不同的界面方向…更新了答案检查它@迈克尔:谢谢你的回答,我试过你的解决方案,但它对我不起作用,也许我弄错了。你能解释一下什么时候弹出横向控制器并按下纵向控制器吗?我要做的是,在视图中,模态控制器将消失,我弹出横向控制器并再次按下。这是对的还是我弄错了?@Michal这不仅仅是两行代码……还有几个类。还需要注册到通知才能获得设备方向更改通知,这也取决于操作系统版本。很抱歉,这对你没有帮助!