在iOS上从横向视图切换到纵向视图

时间:2012-10-16 04:38:57

标签: iphone ios uiview orientation

我的申请表中有两个观点。一个(默认情况下)是Landscape。当用户点击某个菜单时,我需要出现一个纵向视图。

我已经准备好了所有代码,并且我正在尝试使用它:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

但该应用仍会显示Landscape中的下一个视图。我无法弄清楚这一点。任何帮助都会很棒。

2 个答案:

答案 0 :(得分:1)

You can not do it using navigation controller but if you are presenting your view then it  is possible to do that and make sure when you are presenting your view animation should be NO.
It works for me very well.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

答案 1 :(得分:0)

您可以在viewWillAppear方法中使用以下代码制作视图肖像。

 [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];