简体   繁体   English

点击关闭时不要关闭 UIPopoverController

[英]Don't Dismiss UIPopoverController when tap off

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?当用户单击外部某处时,有没有办法使UIPopoverController关闭? 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).我希望用户必须使用取消按钮(是的,我意识到这可能以某种方式违反了 Apple 的 HIG,但这是一种罕见的情况,从用户体验的角度来看是有道理的)。

Thanks for any help.谢谢你的帮助。

Just set the modalInPopover property on the UIViewController being displayed in the UIPopoverController .只需在UIViewController中显示的UIPopoverController上设置modalInPopover属性。

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 .请注意,从 iOS5 开始,您必须在-viewDidAppear modalInPopover

You can do hit-tests on where the tap occurred and in your popover's delegate return NO.您可以对点击发生的位置和弹出框的委托返回 NO 进行命中测试。 - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController

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.如果您使用 Storyboard Segue,您可以在 Segue 上设置 passthrough 属性,以允许与视图中的其他对象进行交互。 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?这里有一些更多的信息: 在 popover segues 中 Anchor 和 Passthrough 是用来做什么的?

And here's a excerpt from the Apple documentation:以下是 Apple 文档的摘录:

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.要允许用户与指定的视图交互而不关闭弹出框,您可以将一个或多个视图分配给 passthroughViews 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM