简体   繁体   English

如何检测弹出窗口关闭

[英]how to detect a popover dismiss

When a popover is open it closes if you click of it.当一个弹出窗口打开时,如果你点击它,它就会关闭。 Is is possible to stop this?有可能阻止吗? Basically i have the following problem.基本上我有以下问题。

When a popover closes i need a function to be processed.当弹出窗口关闭时,我需要处理一个函数。 If i set a button with a dismiss function from the popover then i can put the function in the dismiss method however this isn't detected if the user clicks of the screen.如果我从弹出窗口设置了一个带有关闭功能的按钮,那么我可以将该功能放入关闭方法中,但是如果用户点击屏幕,则不会检测到此功能。

So is is possible to stop a popover closing if you click off it.如果单击关闭,则可以停止弹出窗口关闭。 or Is it possible to detect this allowing the function i require to be called.或者是否可以检测到允许调用我需要的函数。

Thanks谢谢

James詹姆士

Assuming you are talking about the default behavior of popovers being dismissed when you tap outside of the popover, the solution to prevent this is to make the popover modal.假设您正在谈论在弹出框外部点击时弹出弹出框的默认行为,防止这种情况的解决方案是使弹出框模态化。

To do this, set the modalInPopover property to YES on the popover's content view controller.为此,请在弹出窗口的内容视图控制器modalInPopover属性设置为YES

BTW - if you want to detect when a popover is dismissed by the user by tapping outside of it, you need to implement the UIPopoverControllerDelegate method popoverControllerDidDismissPopover: .顺便说一句 - 如果您想通过点击外部来检测弹出窗口何时被用户关闭,您需要实现UIPopoverControllerDelegate方法popoverControllerDidDismissPopover:

Can use these two methods, but the second one suits your scenario:可以使用这两种方法,但第二种方法适合您的场景:

 /* Called on the delegate when the popover controller will dismiss the popover.
    Return NO to prevent the dismissal of the view.
 */
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;

/* Called on the delegate when the user has taken action to dismiss the popover.
   This is not called when -dismissPopoverAnimated: is called directly.
 */
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController;

Remember to implement the UIPopoverdelegate and set the Delegate to self.记得实现 UIPopoverdelegate 并将 Delegate 设置为 self。

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

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