【问题标题】:View Controllers not being displayed in the correct orientation视图控制器没有以正确的方向显示
【发布时间】:2011-02-15 14:26:16
【问题描述】:

假设我在导航控制器层次结构中有三个视图控制器。

这就是我为所有三个视图控制器处理shouldAutorotateToInterfaceOrientation: 消息的方式:

vc1:
{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}

vc2:
{    return (interfaceOrientation == UIInterfaceOrientationPortrait 
  || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
  || interfaceOrientation == UIInterfaceOrientationLandscapeRight);}

vc3:
{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}

所以,我的初始视图控制器 vc1 以纵向模式显示。如果设备旋转,则不会发生任何事情,这是正确的。然后我将 vc2 推到堆栈上,它最初以纵向显示。我旋转设备,vc2 进入横向模式,这是正确的。在剩下的时候,在 vc2 的横向模式下,我将 vc2 从堆栈中弹出并返回到 vc1,然后 vc1 > 以纵向模式显示 - 这也是正确的。

那么问题来了。

vc1纵向显示,弹出到vc2,旋转查看横向。然后,弹出 vc3vc3 以横向模式滑动,尽管它只支持纵向。

我不知道为什么会发生这种情况,也不知道如何应对。换句话说,无论何时回到 vc1,它都会自动以纵向显示,但 vc3 会自动以前一个 vc 使用的任何方向显示。但是你可以看到我对 vc1 和 vc3 使用了相同的代码,所以这对我来说没有意义。

任何帮助将不胜感激!

【问题讨论】:

  • “我对 vc1 和 vc1 使用相同的代码”。你是说vc1和vc3吧?您可能需要对其进行编辑。
  • 是的,谢谢,我的意思是“vc1 和 vc3”,我已经编辑了问题...

标签: iphone sdk view controller orientation


【解决方案1】:

您实际上是如何确定设备方向的?

UIDeviceOrientation 是指错误设备的方向,应与 UIDeviceOrientation... 常量进行比较。

UIInterfaceOrientation 是指界面的方向。它是通过读取statusBar的方向来确定的,应该与UIInterfaceOrientation进行比较。

【讨论】:

  • 我正在使用 shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation。例如,interfaceOrientation 正在与 UIInterfaceOrientationPortrait 进行比较。
猜你喜欢
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多