1

为了避免在意外旋转后弹出框的视图中出现丑陋的 UI 故障带来的巨大麻烦,我只想在发生这种情况时完全关闭弹出框。但是,无论出于何种原因,各种方向通知,例如 (void)willRotateToInterfaceOrientation:duration: 当它们位于弹出框内时都不会被调用。这使得在弹出框的 viewController 中关闭商店变得很困难。

a) 为什么在弹出视图控制器中不会出现方向通知?

b) 处理这些轮换和必要解雇的最佳方式是什么?

4

2 回答 2

1

通常,您的主视图控制器应该收到通知,以便您可以在那里采取行动让您的其他视图控制器执行适当的操作,正在进行的将是使用弹出框注册设备旋转通知并像那样处理它。

于 2010-07-05T23:23:07.923 回答
1

我对上述 (a) 没有答案,但我确实有一个可能适用于 (b) 的可行解决方案......

由于我的一个弹出框是“主菜单”之类的东西,我将它存储在 appDelegate 中。AppDelegate 本身并没有收到“界面旋转”通知,但它确实听到了状态栏方向的变化......

- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
    // a cheat, so that we can dismiss all our popovers, if they're open.

    if (menuPopoverPC) {
        // if we're actually showing the menu, and not the about box, close out any active menu dialogs too
        if (menuPopoverVC && menuPopoverVC == menuPopoverPC.contentViewController)
            [menuPopoverVC.popoverController dismissPopoverAnimated:YES];
        [menuPopoverPC dismissPopoverAnimated:YES];
        menuPopoverPC = nil;
    }
}

另外,我发现的一个小技巧是,每当您执行这些“显示/隐藏”样式的弹出菜单时,通常在所有解雇后您都没有太多机会进行清理。这有时会导致用户必须单击两次才能打开的菜单按钮。也就是说,除非您将控制器设置为 UIPopoverControllerDelegate,否则添加以下内容:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    // the user (not us) has dismissed the popover, let's cleanup.
    menuPopoverPC = nil;
}
于 2010-07-05T23:28:07.040 回答