代码之家  ›  专栏  ›  技术社区  ›  jtrim

shouldAutorotateToInterfaceOrientation在新安装应用程序后首次启动时不起作用

  •  0
  • jtrim  · 技术社区  · 16 年前

    shouldAutorotateToInterfaceOrientation: 一个风景的争论传了进来;调试显示它只被调用为肖像。随后的每一次发射都会像我预期的那样进行——也就是说,有人调用 应自动旋转指向接口方向: 以风景画和肖像画为论据。在iPhone模拟器、iPhone和ipodtouch上都可以看到这种精确的行为。

    所以我的问题是:为什么第一次发布应用程序时的定向通知会与随后每次发布时的定向通知不同?我是否错误地认为我无法控制方向的变化,除了对目标做出反应 应自动旋转指向接口方向: ?

    在有问题的ViewController中:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
     return YES;
    }
    

    在里面 viewDidLoad viewDidUnload 我(分别)有:

     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    

    2010年7月6日更新:

    还是解决不了问题。我放弃了这个问题一段时间,回到它,仍然看到在完全不同的情况下的问题。有人吗?

    2010年7月13日更新:

    从苹果的 View Controller Programming Guide :

    我在第一次启动时将根视图控制器添加到窗口的方式与随后的每次启动不同,所以我想可能与此有关。我还没有找到任何线索…只是一个想法。

    3 回复  |  直到 16 年前
        1
  •  2
  •   jtrim    15 年前

    从来没有解决过这个问题-在我有机会解决之前,我就离开了遇到这个问题的公司。不过,我离开的时候已经有了一个很好的线索。我就这个问题联系了Apple DTS,他们注意到为了让autorotation正常工作,视图堆栈中与autorotation相关的所有ViewController都必须调用方法实现中的超级方法(即调用 [super viewDidLoad] viewDidLoad ). 我不记得他们具体引用了哪些方法,但这可能值得一试,以确保你正确地打电话 super 在适当的情况下。

        2
  •  0
  •   EarlGrey    15 年前

    还要确保设置:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;}
    

    在里面

        3
  •  0
  •   Ash Furrow    14 年前

    我也遇到了类似的问题-UIDevice.h头将endGeneratingDeviceOrientationNotifications和beginGeneratingDeviceOrientationNotifications列为“nestable”,结果发现我对这些方法的调用不平衡。

    我通过对beginGeneratingDeviceOrientationNotifications的以下更改很快解决了这个问题:

    if (![[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];