为了避免一个巨大的麻烦,丑陋的UI故障,从popover的视图后,令人惊讶的旋转,我只想消除所有的popover时,发生这种情况。然而,无论出于什么原因,当定位在弹出窗口中时,诸如(void)willRotateToInterfaceOrientation:duration:之类的各种方向通知不会被调用。这使得关闭popover的viewController中的商店变得困难。
a)为什么在popover viewControllers内部没有出现方向通知?
b)处理这些轮换和必要的解雇的最佳方法是什么?
发布于 2010-07-05 23:23:08
通常情况下,你的主视图控制器应该会收到通知,这样你就可以在那里采取行动,让你的其他视图控制器做适当的动作,正在进行的就是用弹出窗口注册设备旋转通知,并这样处理它。
发布于 2010-07-05 23:28:07
我对上面的(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;
}
https://stackoverflow.com/questions/3182642
复制