点击关闭时不要关闭 UIPopoverController

发布于 2024-11-15 02:51:04 字数 193 浏览 7 评论 0原文

经过一番搜索后,我找不到对许多人有用的答案。

有没有办法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仅冇旳回忆 2024-11-22 02:51:04

只需在 UIPopoverController 中显示的 UIViewController 上设置 modalInPopover 属性即可。

popover = [[UIPopoverController alloc] initWithContentViewController:content];
content.modalInPopover = YES;
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

请注意,从 iOS5 开始,您必须在 内部设置 modalInPopover - viewDidAppear

Just set the modalInPopover property on the UIViewController being displayed in the UIPopoverController.

popover = [[UIPopoverController alloc] initWithContentViewController:content];
content.modalInPopover = YES;
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Be aware that, as of iOS5, you have to set modalInPopover inside of -viewDidAppear.

别再吹冷风 2024-11-22 02:51:04

您可以对点击发生的位置以及弹出窗口的委托返回 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

活雷疯 2024-11-22 02:51:04

所以,我意识到这是一个老问题。然而,对于今天寻找解决方案的人来说,有一个更简单的答案。

如果您使用 Storyboard Segue,则可以在 Segue 上设置 passthrough 属性,以允许与视图中的其他对象进行交互。如果这样做,单击弹出窗口边界之外将不会关闭弹出窗口。

以下是更多信息:
Anchor 和 Passthrough 在 popover segues 中的用途是什么?< /a>

以下是 Apple 文档的摘录:

允许用户与指定的视图交互并且不关闭
弹出窗口,您可以将一个或多个视图分配给 passthroughViews
属性。

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:

To allow the user to interact with the specified views and not dismiss
the popover, you can assign one or more views to the passthroughViews
property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文