开发者

Closing out a UIPopoverController upon orientation change

In order to avoid a huge hassle with ugly UI glitches from the popover's view after a surprise rotation, I just want to dismiss the popover altogether when this happens. However, for whatever reason, the various orientation notifications, such as (void)willRotateToInterfaceOrientation:duration: do not get called when they're located inside a popover. This makes it difficult to close up shop inside that popover's viewController.

a) Why don't orientation notifications occur inside popover viewControllers?

b) What's the best way to deal with these rotations and necessary 开发者_Python百科dismissals?


Generally your main view controller should get the notification so you can take action in there to get your other view controllers to do appropriate actions, under way would be to register for device rotation notifications with the popover and handle it like that.


I don't have an answer to (a) above, but I do have a working solution that might fit apply to (b)...

Since one of my popovers is a "Main Menu" sort of thing, I've got it stored in the appDelegate. AppDelegate doesn't get "interface rotation" notices, per se, but it does hear about status bar orientation changes...

- (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;
    }
}

Also, one little trick I figured out, is whenever you do these Show/Hide style popover menus, oftentimes you don't really get to much opportunity to clean up after all the dismissals. This sometimes leads to a menu button that the user has to click twice to open. That is, unless you set up your controller as a UIPopoverControllerDelegate, then add the following:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    // the user (not us) has dismissed the popover, let's cleanup.
    menuPopoverPC = nil;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜