在特定位置放置一个弹出窗口 [英] Place a pop over on a specific location
问题描述
场景:
我的视图控制器顶部有一个UITabBar。标签栏上有几个按钮。
当用户点击任何按钮时,我想在点按的按钮下方显示一个弹出窗口。
Scenario: I have a UITabBar on the top of my view controller. There are a few buttons on the tabbar. When the user taps on any of the button I want to display a popover just under the button that has been tapped.
我可以显示弹出窗口没问题,但我无法弄清楚如何检测已经按下的按钮的位置,因为UITabItem没有暴露框架结构。
I can display the pop over with no problem but I can't figure out how to detect the location of the button that has been pressed, since the UITabItem doesn't expose a frame structure.
怎么能我解决了我的问题?
How can I solve my problem?
推荐答案
您可以自己计算UITabBarItem的框架:
You can calculate the frame of the UITabBarItem on your own:
CGFloat tabItemWidth = tabBar.bounds.size.width / [tabBar.items count];
CGRect tabItemFrame = CGRectMake(tabItemWidth * [tabBar.items indexOfObject:tabBar.selectedItem], 0, tabItemWidth, tabBar.bounds.size.height);
(我没有尝试过这段代码,但是这个或类似的东西应该可以工作)。
(I haven't tried this code, but this or something like it should work).
或者,您应该能够继承UITabBar并覆盖touchesEnded:withEvent:。在该方法中,将触摸的位置存储在ivar中。然后在你的UITabBarDelegate的tabBar:didSelectItem:你可以使用touch的位置。
Or, you should be able to subclass UITabBar and override touchesEnded:withEvent:. In that method, store the location of the touch in an ivar. Then in your UITabBarDelegate's tabBar:didSelectItem: you can use the touch's location.
这篇关于在特定位置放置一个弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!