UIPopoverController的位置

我正在开发一个应用程序,这个应用程序应该是通用的,一个用于iPad和iPhone的应用程序。 我想保持它们的接口尽可能相似。 在iPhone应用程序中,我使用了一个选项卡栏控制器,其中一个选项卡会转到图像选取器控制器。 很明显,我不能在iPad上做到这一点。 所以我已经劫持了该button的控制,以带有一个popup在图像select器中的popupcontroller。 这一切都工作得很好,除非我popuppopup窗口,它不是在正确的位置。 当我旋转模拟器,popup去正确的地方,并保持我甚至回转。

我的代码是基于这个问题的代码: Ipad UIImagePickerController和UIPopoverController错误

为什么我的popup不在正确的位置?

如果您的代码基于您引用的问题,那么看起来您使用以下代码来显示popup窗口:

[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES] 

UIPopoverController:presentPopoverFromBarButtonItem:allowedArrowDirections:animation接受一个UIBarButtonItem *为您的UITabBar没有的发件人。 UITabBar使用具有UIBarItem的基础的UITabBarItem。 UIBarButtonItem也有这个基础(UIBarItem)。

无论如何…我还需要从tabbaritem显示一个uipopovercontroller,我用下面的代码:

 MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:myVC]; [myVC release]; popover.popoverContentSize = myVC.view.frame.size; popover.delegate = self; int tabBarItemWidth = self.tabBar.frame.size.width / [self.tabBar.items count]; int x = tabBarItemWidth * 6; CGRect rect = CGRectMake(x, 0, tabBarItemWidth, self.tabBar.frame.size.height); [popover presentPopoverFromRect:rect inView:self.tabBar permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 

注意:你的x计算将会不同。 为我select的标签栏项目是第六个。 基本上

 x = tabBarItemWidth * currentTabBarItemIndex;