UIPopoverController 放置

发布于 2024-10-21 19:52:31 字数 458 浏览 8 评论 0原文

我正在开发一款应该是通用的应用程序,一款同时适用于 iPad 和 iPhone 的应用程序。我想让他们的界面尽可能相似。在 iPhone 应用程序中,我使用选项卡栏控制器,其中一个选项卡转到图像选择器控制器。显然我无法在 iPad 上做到这一点。因此,我劫持了该按钮的控制权,以引入一个包含图像选择器的弹出控制器。这一切都运行得很好,除了当我打开弹出窗口时,它不在正确的位置。当我旋转模拟器时,弹出窗口会转到正确的位置,并且当我向后旋转时,弹出窗口会保持不变。

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

为什么我的弹出窗口不在正确的位置?

I'm working on an app that is supposed to be universal, one app for both iPad and iPhone. I would like to keep their interfaces as similar as possible. In the iPhone app I am using a Tab bar controller, and one of those tabs goes to an image picker controller. Obviously I cannot do that in iPad. So I have hijacked control of that button to bring a popupcontroller that has the image picker in it. This all works well enough, except when I bring up the popup, it is not in the correct place. When I rotate the simulator, the popup goes to the correct place, and stays when I rotate back even.

My code is based on the code in this question:
Ipad UIImagePickerController and UIPopoverController error

Why would my popup not be in the correct location?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2024-10-28 19:52:31

如果您的代码基于您引用的问题,则您似乎正在使用以下代码来显示弹出窗口:

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

UIPopoverController:presentPopoverFromBarButtonItem:permissedArrowDirections:animated 接受 UITabBar 没有的发件人的 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 计算将会有所不同。为我选择的选项卡栏项目是第六个。
基本上

x = tabBarItemWidth * currentTabBarItemIndex;

If your code is based on the question you referenced, it would appear you are using the following code to show the popover:

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

UIPopoverController:presentPopoverFromBarButtonItem:permittedArrowDirections:animated accepts a UIBarButtonItem* for the sender which your UITabBar does not have. UITabBar uses UITabBarItem which has a base of UIBarItem. UIBarButtonItem also has that base (UIBarItem).

Anyhow... I also needed to show a uipopovercontroller from a tabbaritem, I used the following code:

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];

Note: your x calculation will be different. The tab bar item selected for me was the 6th one.
Basically

x = tabBarItemWidth * currentTabBarItemIndex;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文