Don't Dismiss UIPopoverController when tap off

走远了吗. 提交于 2019-12-06 17:46:41

问题


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.


回答1:


You can do hit-tests on where the tap occurred and in your popover's delegate return NO. - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6332592/dont-dismiss-uipopovercontroller-when-tap-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!