【问题标题】:Having trouble with interface orientation on iPadiPad 上的界面方向有问题
【发布时间】:2011-10-22 16:25:55
【问题描述】:

我正在为 Xcode 4 上的 iPad 应用程序提供帮助。我知道有

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

如果你想支持所有方向,那应该返回 YES。以前,该应用程序卡在横向模式。我正在尝试更改视图以支持所有方向。所以我改变了该方法的出现以返回 YES 而不是只为 LandscapeLeft 和 LandscapeRight 方向返回 YES。但是,当我尝试这样做时:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
            NSLog(@"%i, %s", self.interfaceOrientation, __FUNCTION__);
}

我总是在控制台中得到 3 或 4,这是两个横向方向。当您单击项目图标时,我检查了“摘要”页面,并且支持所有设备方向。在 .plist 文件中,列出了所有方向。还有其他地方可以设置我忽略的吗?谢谢。

【问题讨论】:

  • 不知道这是否有帮助,但它可以从某个地方开始 - stackoverflow.com/questions/2868132/…
  • 听起来这里发生了其他事情。尝试监听方向变化的全局 NSNotification,然后与您的日志进行比较。

标签: iphone ipad


【解决方案1】:

我在使用呈现子视图控制器的自定义导航控制器时遇到了同样的问题。就我而言,我使用表格视图在网格中显示项目,并且我需要我的表格视图单元格根据方向显示不同数量的项目。这是我找到的解决方法:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    // we have to use self.view.window.rootViewController.interfaceOrientation because for some reason
    // self.interfaceOrientation isn't updating.  That's what I get for using custom navigation, I guess.
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    if (!self.isViewLoaded) {
        return;
    }
    if (self.view.window) {
        if (UIInterfaceOrientationIsPortrait(self.view.window.rootViewController.interfaceOrientation) != UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) {
            // if we are rotating between portrait and landscape, we'll have to reload the data
            [self.tableView reloadData];
        }
    } else {
        self.needsReloadData = YES;
    }
}

通过从窗口的根视图控制器读取方向,您可以可靠地确定设备的实际方向。不幸的是,如果视图控制器的视图已从当前窗口中删除,self.view.window 将返回nil,所以在这种情况下,我必须在viewDidAppear 中提出一个标志并处理它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    相关资源
    最近更新 更多