How can I have a popover come from a tab instead of a view

北城余情 提交于 2019-11-28 10:30:56

问题


I have a tabbar app, and I want a popover to come from one of the tabs. Is there a good/easy way to do this without changing views?


回答1:


There isn't currently a way to directly (through a supported api call) get the frame of a specific tab bar item. What I do is just show the popup from the left end of the tab bar like this:

CGFloat tabBarHeight = self.tabBarController.tabBar.bounds.size.height;
CGRect rect = CGRectMake(0, 0, tabBarHeight, tabBarHeight);
[popoverController presentPopoverFromRect:rect 
    inView:self.tabBarController.tabBar 
    permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

You could try to estimate the position of the tab bar item taking the current orientation into account if you really wanted to and adjust the X coordinate of the rect above.

You could also look through the subviews of the tabbar and find the UITabBarButton object but that's not documented so it's not recommended.



来源:https://stackoverflow.com/questions/4405350/how-can-i-have-a-popover-come-from-a-tab-instead-of-a-view

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