点击 UIBarButtonItem 后关闭 UIPopoverController(如果可见)
如果/当另一个 UIBarButtonItem 被点击时,我试图关闭任何当前可见的 UIPopoverControllers,如在样式/媒体/工具等之间点击时在 iPad 的页面上看到的那样。
我已经这样做了,但它太具体了。寻找通用的东西。
if ([popoverController isPopoverVisisble]) {
[popoverController dismissPopoverAnimated:YES];
}
谢谢!
I'm trying to dismiss any currently visible UIPopoverControllers if/when another UIBarButtonItem is tapped as seen on Pages for the iPad when tapping between Styles/Media/Tools etc.
I've done this, but it's too specific. Looking for something generic.
if ([popoverController isPopoverVisisble]) {
[popoverController dismissPopoverAnimated:YES];
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否设置了弹出窗口控制器的 passthroughViews 属性?如果您这样做,那么点击弹出窗口外部将不会导致弹出窗口自动关闭,而是会被发送到该数组中的视图。您应该能够将 UIBarButtonItem 添加到此数组,然后关闭该处理程序中的弹出窗口。
Did you set the passthroughViews property of the popover controller? If you do this, then taps outside the popover will not cause the popover to automatically dismiss, but will instead be sent to the views in that array. You should be able to add the UIBarButtonItem to this array, and then dismiss the popover in that handler.
兰德尔梅多斯的回答不会起作用。 UIBarButtonItem 不是 UIView 的后代,这意味着您无法将其添加到 passthroughViews 中。
我现在找到的唯一解决方案是使用自定义 UIButton 创建 UIBarButtonItem
,然后使用,
但要做好准备,您将失去所有样式 - 您不能太容易创建看起来像 UIBarButtoItem 的 UIButton。
randallmeadows answer will NOT work. UIBarButtonItem is not descendant of UIView, which means you cannot add it to passthroughViews.
The only solution I found for now is to create UIBarButtonItem with custom UIButton using
and then
But be prepared that you'll loose all the styling - you cannot create UIButton that looks like UIBarButtoItem too easily.
对我有用
Works for me