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

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

4

3 回答 3

1

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

所以我这样做:

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

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

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

获取项目的宽度中心。

于 2011-07-07T07:25:36.927 回答
0

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

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

[pop presentPopoverFromRect:CGRectMake(100,100,100,100) permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
于 2011-07-04T23:27:09.793 回答
0

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

这种方法似乎属于 App Store 安全编码的范围,特别是如果您回退到仅使用标签栏(frame如果操作系统升级破坏了您的代码)。

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

(gdb) po [[[[[UIApplication sharedApplication] delegate] tabBarController] view] recursiveDescription]
于 2012-02-13T17:20:53.283 回答