有没有办法在按下弹出框外部时不让弹出框消失?
我知道 SDK 文档说
点击弹出窗口内容之外的区域会自动关闭弹出窗口。
但我确信这里的聪明人找到了方法:) 也许我应该覆盖弹出窗口关闭功能?
谢谢
编辑: 我尝试按照此处的建议使用 passthroughViews,并且效果完美。下面是任何需要它的人的代码 - 在这个示例中,我将 self.view 放入数组中,这意味着无论在弹出窗口起源的按钮之外,都不会关闭弹出窗口。
popoverController.passthroughViews = [[[NSArray alloc] initWithObjects:self.view, nil] autorelease];
I know the SDK documentation says
Taps outside of the popover’s contents automatically dismiss the popover.
But I'm sure the smart people here found a way :)
maybe I should overwrite the popover dismiss function?
Thanks
EDIT:
I tried using the passthroughViews as was suggested here, and it works perfectly. Here's the code for whoever needs it - in this example, I put self.view in the array, which means that where ever outside the button where the popover was originated, nothing dismiss the popover.
popoverController.passthroughViews = [[[NSArray alloc] initWithObjects:self.view, nil] autorelease];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要设置
passthroughViews
属性。从文档中:将
passthroughViews
设置为您想要处理触摸事件而不是仅仅关闭弹出窗口的视图数组。You need to set the
passthroughViews
property. From the documentation:Set
passthroughViews
to an array of view(s) that you want to handle the touch event instead of just dismissing the popover.有一个非常简单且合法的解决方案。在呈现
UIPopoverController
的视图控制器中,遵循UIPopoverControllerDelegate
协议并实现以下委托方法。我刚刚测试了这个,它确实阻止了弹出窗口的关闭。只需确保您已将弹出窗口控制器的委托设置为实现此功能的视图控制器。
您可以使用
[popoverController DismissPopoverAnimated:NO];
方法关闭弹出窗口。There is a very simple and legit solution. In the view controller that presents your
UIPopoverController
, conform to theUIPopoverControllerDelegate
protocol and implement the following delegate method. I just tested this and it does prevent popover to dismiss.Just make sure that you have set the delegate of your popover controller to the view controller that implements this.
You can dismiss the popover by using
[popoverController dismissPopoverAnimated:NO];
method.接受的答案并没有真正回答这个问题,“有没有办法在按下弹出框之外时不让弹出框消失?”,我认为。它确实提供了一个可能的视图,但可能需要对所有父视图进行黑客访问并确定屏幕上有哪些视图等。这个问题可以改写为“如何制作弹出视图模式?”
您可以像这样执行此操作,使用完成按钮来关闭弹出窗口:
然后您将在 processDoneAction 方法中需要关闭弹出窗口。其他考虑因素是在设备方向更改时忽略并重新显示,但我将把它留给另一个练习,因为之前已经在 stackoverflow 上回答过。
The accepted answer does not really answer the question, "is there a way NOT to have the popover dismissed when pressing outside it?", imo. It does give a possible view but could require hackish access to all parent views and determining what views are on the screen etc. The question could be rephrased as, "how do I make a popover view modal?"
You would do this like so, with a done button to close the popover:
Then you'll in your processDoneAction method you will need to dismiss the popover. Other considerations would be dismissing and redisplaying on device orientation changes, but I will leave that to another exercise as that has been answered previously on stackoverflow.