gpt4 book ai didi

ios - 对话框打开时如何识别模态对话框外的点击手势

转载 作者:行者123 更新时间:2023-11-28 20:21:15 24 4
gpt4 key购买 nike

我只想知道当用户在模式对话框之外点击时如何识别。我试过这个,但是当用户在外面点击时它没有被调用。

这是我的 viewDidLoad 方法,它位于 ModalDialogViewController.m 文件中 UITapGestureRecognizer *识别器;

        if(![self.view.window.gestureRecognizers containsObject:recognizer])
{
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
//[recognizer setDelegate:self];
[recognizer setNumberOfTapsRequired:1];
recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
[self.view.window addGestureRecognizer:recognizer];

}

这不是打开 handleTapBehind 方法。

我已将模态视图 Controller 设为 UIGestureRecognition 协议(protocol)。

最佳答案

这里有点晚了,但万一有人通过谷歌来到这里:

应该在 View 出现后设置手势识别器。在 viewDidLoad 方法调用期间, View 的窗口为 nil,因此永远不会添加手势识别器。

将方法调用放在 viewDidAppear 中,它应该会按预期工作。

关于ios - 对话框打开时如何识别模态对话框外的点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15874643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com