点击关闭时不要关闭 UIPopoverController
经过一番搜索后,我找不到对许多人有用的答案。
有没有办法让 UIPopoverController
当用户点击外部某处时不关闭?我希望用户必须使用取消按钮(是的,我意识到这可能在某种程度上违反了 Apple 的 HIG,但这是一种罕见的情况,从用户体验的角度来看是有意义的)。
感谢您的任何帮助。
after a bit of searching, I couldn't find an answer to something that seems like it would be useful to many.
Is there a way to make a UIPopoverController
not dismiss when the user clicks somewhere on the outside? I want the user to have to use a cancel button (Yes, i realize this probably violates Apple's HIG somehow, but it's a rare case and makes sense from a User experience perspective).
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在
UIPopoverController
中显示的UIViewController
上设置modalInPopover
属性即可。请注意,从 iOS5 开始,您必须在
内部设置
。modalInPopover
- viewDidAppearJust set the
modalInPopover
property on theUIViewController
being displayed in theUIPopoverController
.Be aware that, as of iOS5, you have to set
modalInPopover
inside of-viewDidAppear
.您可以对点击发生的位置以及弹出窗口的委托返回 NO 进行命中测试。
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
You can do hit-tests on where the tap occurred and in your popover's delegate return NO.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
所以,我意识到这是一个老问题。然而,对于今天寻找解决方案的人来说,有一个更简单的答案。
如果您使用 Storyboard Segue,则可以在 Segue 上设置 passthrough 属性,以允许与视图中的其他对象进行交互。如果这样做,单击弹出窗口边界之外将不会关闭弹出窗口。
以下是更多信息:
Anchor 和 Passthrough 在 popover segues 中的用途是什么?< /a>
以下是 Apple 文档的摘录:
So, I realize this is an old question. However, there's an easier answer for anyone searching for a solution today.
If you use a Storyboard Segue, you can set the passthrough property on the segue allowing interaction with other objects in the view. If you do so, clicking outside of the bounds of the popover won't close the popover.
Here's some more info:
What are Anchor and Passthrough used for in popover segues?
And here's a excerpt from the Apple documentation: