UIPopoverController placement

别来无恙 提交于 2019-12-01 14:41:11

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!