【问题标题】:using the device orientation to implement a modal view controller使用设备方向来实现模态视图控制器
【发布时间】:2011-01-29 20:54:01
【问题描述】:

请原谅我一个菜鸟问题,这是我的第一个问题,老实说,我花费了相当大的精力寻找自己的解决方案。

我有一个带有两个视图控制器的项目。 main on 仅是纵向视图,第二个(子)模态视图控制器仅以横向模式显示。我的目标是让设备的方向单独切换控制器(并提供对模态视图控制器的函数调用,同时从主视图控制器传递某些 ivars)同样我想重新定向到纵向关闭模态视图并返回到起点。

我想这有点像苹果自己的计算器应用程序的工作原理?任何人都可以给我一个关于最符合 API 的方法的线索吗? 非常感谢您的宝贵时间。

我非常希望避免在模态视图上出现“返回”或“完成”按钮,并且只有在可能的情况下才能随着设备方向来回更改

【问题讨论】:

  • 你所说的(子)模态是什么意思?您确定您的视图控制器之一必须是模态的吗?
  • Kris,嗨.. 不,我不太确定我是否需要第二个控制器,也许只是一堆不同的视图..

标签: iphone view controller modal-dialog


【解决方案1】:

Apple 为您想要做的事情提供了很好的解释和示例代码。请参阅视图控制器编程指南中的Creating an Alternate Landscape Interface

【讨论】:

    【解决方案2】:

    如果您为视图启用了旋转,那么在 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 您可以检查方向和相应的行为,如下所示:

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    
        if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
        {
         //check if modal viewController is already alive 
         //pop the modal if needed
        }
       else
        {
        //destory the modal if its still alive
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多