iPhone:从 tabBarItem 显示 popOver

发布于 2024-11-18 13:58:17 字数 3621 浏览 3 评论 0原文

我想知道如何从 tabBarItem 显示 popOver ? 这是我管理 tabBarController 的方式:

tabBarController = [[UITabBarController alloc] init];

searchSplitViewController = [[UISplitViewController alloc] init];
searchRoot = [[[EI_iPad_Home_Root_ViewController alloc] init] autorelease];
searchDetail = [[[EI_iPad_Home_Detail_ViewController alloc] init] autorelease]; 
searchRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:searchRoot]autorelease];
searchDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:searchDetail] autorelease];
searchSplitViewController.viewControllers = [NSArray arrayWithObjects:searchRootNav, searchDetailNav, nil];
searchSplitViewController.delegate = searchDetail;

favoritesSplitViewController = [[UISplitViewController alloc] init];
favoritesRoot = [[[EI_iPad_Favorites_Root_ViewController alloc] init] autorelease];
favoritesDetail = [[[EI_iPad_Favorites_GeneralDetail_ViewController alloc] init] autorelease]; 
favoritesRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:favoritesRoot]autorelease];
favoritesDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:favoritesDetail] autorelease];
favoritesSplitViewController.viewControllers = [NSArray arrayWithObjects:favoritesRootNav, favoritesDetailNav, nil];
favoritesSplitViewController.delegate = favoritesDetail;

agencySplitViewController = [[UISplitViewController alloc] init];
agencyRoot = [[[EI_iPad_Agency_Root_ViewController alloc] init] autorelease];
agencyDetail = [[[EI_iPad_Agency_GeneralDetail_ViewController alloc] init] autorelease]; 
agencyRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:agencyRoot]autorelease];
agencyDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:agencyDetail] autorelease];
agencySplitViewController.viewControllers = [NSArray arrayWithObjects:agencyRootNav, agencyDetailNav, nil];
agencySplitViewController.delegate = agencyDetail;

editoSplitViewController = [[UISplitViewController alloc] init];
editoRoot = [[[EI_iPad_News_Root_ViewController alloc] init] autorelease];
editoDetail = [[[EI_iPad_News_Detail_ViewController alloc] init] autorelease]; 
editoRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:editoRoot]autorelease];
editoDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:editoDetail] autorelease];
editoSplitViewController.viewControllers = [NSArray arrayWithObjects:editoRootNav, editoDetailNav, nil];
editoSplitViewController.delegate = editoDetail;

searchSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_search_label",nil);
searchSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_search_icon.png"];

favoritesSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_favorite_label",nil);
favoritesSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_favorite_icon.png"];

agencySplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_agencies_label",nil);
agencySplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_agencies_icon.png"];

editoSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_news_label",nil);
editoSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_news_icon.png"];

tabBarController.viewControllers = [NSArray arrayWithObjects:searchSplitViewController,favoritesSplitViewController,agencySplitViewController,editoSplitViewController,nil];
[window addSubview:[tabBarController view]];

我想添加第五个项目,它将显示一个弹出窗口......有什么想法吗?谢谢

I wonder how I can display a popOver from a tabBarItem ?
Here is how I manage my tabBarController :

tabBarController = [[UITabBarController alloc] init];

searchSplitViewController = [[UISplitViewController alloc] init];
searchRoot = [[[EI_iPad_Home_Root_ViewController alloc] init] autorelease];
searchDetail = [[[EI_iPad_Home_Detail_ViewController alloc] init] autorelease]; 
searchRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:searchRoot]autorelease];
searchDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:searchDetail] autorelease];
searchSplitViewController.viewControllers = [NSArray arrayWithObjects:searchRootNav, searchDetailNav, nil];
searchSplitViewController.delegate = searchDetail;

favoritesSplitViewController = [[UISplitViewController alloc] init];
favoritesRoot = [[[EI_iPad_Favorites_Root_ViewController alloc] init] autorelease];
favoritesDetail = [[[EI_iPad_Favorites_GeneralDetail_ViewController alloc] init] autorelease]; 
favoritesRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:favoritesRoot]autorelease];
favoritesDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:favoritesDetail] autorelease];
favoritesSplitViewController.viewControllers = [NSArray arrayWithObjects:favoritesRootNav, favoritesDetailNav, nil];
favoritesSplitViewController.delegate = favoritesDetail;

agencySplitViewController = [[UISplitViewController alloc] init];
agencyRoot = [[[EI_iPad_Agency_Root_ViewController alloc] init] autorelease];
agencyDetail = [[[EI_iPad_Agency_GeneralDetail_ViewController alloc] init] autorelease]; 
agencyRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:agencyRoot]autorelease];
agencyDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:agencyDetail] autorelease];
agencySplitViewController.viewControllers = [NSArray arrayWithObjects:agencyRootNav, agencyDetailNav, nil];
agencySplitViewController.delegate = agencyDetail;

editoSplitViewController = [[UISplitViewController alloc] init];
editoRoot = [[[EI_iPad_News_Root_ViewController alloc] init] autorelease];
editoDetail = [[[EI_iPad_News_Detail_ViewController alloc] init] autorelease]; 
editoRootNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:editoRoot]autorelease];
editoDetailNav = [[[EI_Navigation_ViewController alloc] initWithRootViewController:editoDetail] autorelease];
editoSplitViewController.viewControllers = [NSArray arrayWithObjects:editoRootNav, editoDetailNav, nil];
editoSplitViewController.delegate = editoDetail;

searchSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_search_label",nil);
searchSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_search_icon.png"];

favoritesSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_favorite_label",nil);
favoritesSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_favorite_icon.png"];

agencySplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_agencies_label",nil);
agencySplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_agencies_icon.png"];

editoSplitViewController.tabBarItem.title = NSLocalizedString(@"TabBar_news_label",nil);
editoSplitViewController.tabBarItem.image = [UIImage imageNamed:@"tabBar_news_icon.png"];

tabBarController.viewControllers = [NSArray arrayWithObjects:searchSplitViewController,favoritesSplitViewController,agencySplitViewController,editoSplitViewController,nil];
[window addSubview:[tabBarController view]];

I want to add a fifth item which will display a popover... any idea ? Thanks

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

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

发布评论

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

评论(3

我家小可爱 2024-11-25 13:58:17

为了获得我的 UITabBarItem 框架,我注意到在 iPad 上(iPhone 上的项目是 autorisizingWidth,这更简单)项目的宽度为 75px,间距为 34px。

所以我这样做:

(tabBar.frame.size.width-((75*[tabBarController.items count])+(34*[tabBarController.items count]-1)))/2

获得第一个灵活的空间宽度。
然后我添加:

(75*indexOfItemToReach)+(34*(indexOfItemToReach-1))+(75/2)

获取项目的宽度中心。

To get my UITabBarItem frame I noticed that on the iPad (on iPhone items are autorisizingWidth it's more simple) items are 75px width and are spaced by 34px.

So I do :

(tabBar.frame.size.width-((75*[tabBarController.items count])+(34*[tabBarController.items count]-1)))/2

to get the first flexible sapce width.
Then I add :

(75*indexOfItemToReach)+(34*(indexOfItemToReach-1))+(75/2)

To get the width center of the item.

So要识趣 2024-11-25 13:58:17

我建议不要这样做,因为这不是选项卡栏的预期行为。但是,您可以创建一个 UIPopoverController 并使用presentPopoverFromRect 显示它。

UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:someVC];

[pop presentPopoverFromRect:CGRectMake(100,100,100,100) permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

I would advice against this because that's not the expected behavior for a tab bar. However, you could create a UIPopoverController and display it using presentPopoverFromRect.

UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:someVC];

[pop presentPopoverFromRect:CGRectMake(100,100,100,100) permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
ま柒月 2024-11-25 13:58:17

您可以抓取选项卡栏的视图层次结构并查找 UIControl 子类(它们可能以随机顺序出现,因此您需要按照 center.x 最左边的顺序对它们进行排序)。每个按钮都是一个标签栏按钮,其中有一个矩形。

这种方法似乎属于应用程序商店安全编码的范围,特别是如果操作系统升级破坏了您的代码,您只能使用选项卡栏的框架

UIView 有一个方便的未记录方法,称为“recursiveDescription”,对于调试非常有用。例如:

(gdb) po [[[[[UIApplication sharedApplication] delegate] tabBarController] view] recursiveDescription]

You can crawl the tab bar's view hierarchy and look for UIControl subclasses (they may come up in random order, so you'll want to sort them by which one's center.x is leftmost). Each one is a tab bar button, which will have a rect.

This approach appears to be within the realm of App Store-safe coding, particularly if you fall back to just using the tab bar's frame if an OS upgrade breaks your code.

UIView has a handy undocumented method called recursiveDescription that's incredibly useful for debugging. E.g.:

(gdb) po [[[[[UIApplication sharedApplication] delegate] tabBarController] view] recursiveDescription]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文