Iphone 在纵向UIAbbarController/UINavigationController中显示横向UIViewController
我知道这个问题(或它的变体)已经被问了好几次了,但是它仍然是如何最好地解决这个问题而不去钻研那些乱七八糟的黑客 我有一个布局如下的应用程序:Iphone 在纵向UIAbbarController/UINavigationController中显示横向UIViewController,iphone,cocoa-touch,uikit,Iphone,Cocoa Touch,Uikit,我知道这个问题(或它的变体)已经被问了好几次了,但是它仍然是如何最好地解决这个问题而不去钻研那些乱七八糟的黑客 我有一个布局如下的应用程序: UITabBarController ↳ UINavigationController ↳ PortraitViewController ↳ LandscapeViewController 第一个肖像视图控制器将其rightBarButtonItem设置为UIBarButtonItem,它调用landscapeButt
UITabBarController
↳ UINavigationController
↳ PortraitViewController
↳ LandscapeViewController
第一个肖像视图控制器
将其rightBarButtonItem
设置为UIBarButtonItem
,它调用landscapeButtonPressed:
。该方法将LandscapeViewController
推送到视图控制器堆栈上
在LandscapeViewController
中,我在初始化过程中将hidesbottombarwhenpush
设置为YES
,因为我只希望导航栏可见
我还在loadView
中调用SetStatusBaroOrientation:UIInterfaceOrientation和scapeRight
,视图将出现:
,然后将其设置回视图中的UIInterfaceOrientation纵向
将消失:
在我的shouldAutorotateToInterfaceOrientation:
实现中,我仅为UIInterfaceOrientation和scapeRight返回YES
ViewController
如下所示:
LandscapeViewController
如下所示:
如您所见,视图旋转不正确。如果在调用-[UIApplication setStatusBaroOrientation:
之前调用private-[UIDevice setOrientation:
方法,我可以使导航栏正确旋转,但我宁愿不调用private方法,而且似乎没有办法获得主视图的边界来布局子视图。使用private方法会产生以下结果:
有什么办法解决这个问题吗
我的目标是拥有一个横向视图,具有有效的横向CGRect坐标,我可以将其用作布局子视图的基础。由于interfaceOrientation
是UIInterfaceOrientation和scapeRight
,因此LandscapeViewController不会自动旋转,因此,对于UIInterfaceOrientationAndscapeRight
要正确调整视图大小,必须使用Interface Builder打开xib文件,然后进入Inspector,最后进入“大小”选项卡
我觉得您已将肖像ViewController设置为UINavigationController的rootViewController。我还认为,在shouldAutorotateToInterfaceOrientation方法中,您仅将肖像视图控制器的方向限制为UIInterfaceOrientationGrait。如果是这样,则推送的任何视图控制器都将具有rootViewController本身的方向,除非您没有通过旋转设备来更改设备方向
因此,如果您需要UIInterfaceOrientation和ScapeRight方向中的LandscapeViewController,则只需在shouldAutorotateToInterfaceOrientation:方法中允许此操作,并且不要通过显式设置设备方向来搞砸事情。正如我在问题中所说,我已经在景观控制器中为返回了YES
。我确信您已经编写了UIInterfaceOrientation和scapeLeft
而不是UIInterfaceOrientation和scapeRight
。。。我的错误。