Ipad 方向改变时关闭超控器

Ipad 方向改变时关闭超控器,ipad,orientation,uipopovercontroller,Ipad,Orientation,Uipopovercontroller,为了避免在突然轮换后popover视图中出现丑陋的UI故障带来的巨大麻烦,我只想在出现这种情况时将popover完全忽略。但是,无论出于何种原因,各种方向通知,例如(void)willRotateToInterfaceOrientation:duration:位于popover内时不会被调用。这使得很难在popover的viewController中关闭店铺 a) 为什么popover ViewController中不会出现方向通知? b) 处理这些轮换和必要解雇的最佳方式是什么? 一般来说,您

为了避免在突然轮换后popover视图中出现丑陋的UI故障带来的巨大麻烦,我只想在出现这种情况时将popover完全忽略。但是,无论出于何种原因,各种方向通知,例如(void)willRotateToInterfaceOrientation:duration:位于popover内时不会被调用。这使得很难在popover的viewController中关闭店铺

a) 为什么popover ViewController中不会出现方向通知? b) 处理这些轮换和必要解雇的最佳方式是什么?

一般来说,您的主视图控制器应该收到通知,这样您就可以在那里采取行动,让其他视图控制器执行适当的操作,正在进行的是向popover注册设备旋转通知,并像这样处理。

我没有上述(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;
}

啊!!我没有想过要在popover中明确注册设备旋转。我喜欢这种方法。至于使用mainViewController来执行操作,这对许多人来说应该是可行的,但在我的例子中,这个菜单弹出窗口将在应用程序的各个阶段的大量DetailViewController中出现,因此为了安全起见,我将它移到了appDelegate中。