我正在开发一个应该是通用的应用程序,一个既适用于iPad又适用于iPhone的应用程序。我想让他们的界面尽可能的相似。在iPhone应用程序中,我使用的是选项卡栏控制器,其中一个选项卡转到了图像拾取器控制器。显然,在iPad中我无法做到这一点。因此,我劫持了对该按钮的控制,以带来一个包含图像拾取器的popupcontroller。这一切都运行得很好,除了当我弹出弹出窗口时,它不在正确的位置。当我旋转模拟器时,弹出窗口会移动到正确的位置,即使我旋转回来,弹出窗口也会一直保持不动。
我的代码基于这个问题中的代码:Ipad UIImagePickerController and UIPopoverController error
为什么我的弹出窗口不在正确的位置?
发布于 2011-03-12 05:48:03
如果您的代码基于您引用的问题,则您似乎正在使用以下代码来显示弹出窗口:
[popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES]对于您的UITabBar没有的发件人,UIPopoverController:presentPopoverFromBarButtonItem:permittedArrowDirections:animated接受UIBarButtonItem*。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计算将有所不同。为我选择的选项卡栏项目是第6个。基本上
x = tabBarItemWidth * currentTabBarItemIndex;https://stackoverflow.com/questions/5278236
复制相似问题