UIPopoverController放置 [英] UIPopoverController placement

查看:93
本文介绍了UIPopoverController放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款应该是通用的应用,一款适用于iPad和iPhone的应用。我想保持他们的接口尽可能相似。在iPhone应用程序中,我使用的是Tab栏控制器,其中一个选项卡转到图像选择器控制器。显然我不能在iPad上做到这一点。所以我劫持了对该按钮的控制,带来了一个带有图像选择器的popupcontroller。这一切都运行得很好,除非我弹出弹出窗口,它不在正确的位置。当我旋转模拟器时,弹出窗口会转到正确的位置,并在我向后旋转时停留。

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.

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

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?

推荐答案

如果您的代码基于您引用的问题,您似乎使用以下代码来显示popover:

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:allowedArrowDirections:animated接受UITabBar没有的发件人的UIBarButtonItem *。 UITabBar使用UITabBarItem,它具有UIBarItem的基础。 UIBarButtonItem也有这个基础(UIBarItem)。

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).

无论如何......我还需要从tabbaritem显示一个uipopovercontroller,我使用了以下代码:

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

注意:你的x计算会有所不同。为我选择的标签栏项目是第6个。
基本上

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

x = tabBarItemWidth * currentTabBarItemIndex;

这篇关于UIPopoverController放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆