我可以通过触摸 DialogViewController (MonoTouch.Dialog) 的背景来关闭 iPhone 键盘吗?

发布于 2024-09-13 13:57:43 字数 483 浏览 3 评论 0原文

可能的重复:
MonoTouch.Dialog:通过触摸 DialogViewController 中的任意位置来关闭键盘

我正在使用 MonoTouch.Dialogs 中的 DialogViewController。我希望能够通过单击对话框的背景来关闭键盘。

我通常采用用大的自定义按钮填充视图并将其放置在所有其他元素后面的技术。但是,我无法在 DialogViewController 中完成这项工作。我在 LoadView 中执行了此操作,它只是冻结了所有其他控件。

有没有一种相对简单的方法来实现我想要的?

Possible Duplicate:
MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController

I'm using DialogViewController from MonoTouch.Dialogs. I'd like to be able to dismiss the keyboard by clicking on the background of the dialog.

I usually employ the technique of filling the view with a large custom button and placing it behind all the other elements. However, I can't make this work in the DialogViewController. I did this in LoadView and it just froze all the other controls.

Is there a relatively straightforward way of achieving what I want?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

世界和平 2024-09-20 13:57:43

在视图控制器中:

public override void TouchesBegan (NSSet touches, UIEvent evt)
    {
        base.TouchesBegan (touches, evt);

        myField.ResignFirstResponder();
    }

编辑:根据我的阅读,您可以使用单元格子视图的 TouchesBegan 事件而不是表本身。我不确定这是否有效。祝你好运 :)

In view controller:

public override void TouchesBegan (NSSet touches, UIEvent evt)
    {
        base.TouchesBegan (touches, evt);

        myField.ResignFirstResponder();
    }

Edit: From what I've read, you can use the TouchesBegan event for the cell subview instead of the table itself. I'm not positive that works. Good luck :)

淡淡的优雅 2024-09-20 13:57:43

miguel.de.icaza 在另一个线程上回答了这个问题:
https://stackoverflow.com/a/10864640/1134836

他的解决方案:

 var tap = new UITapGestureRecognizer ();
   点击.AddTarget(() =>{
       dvc.View.EndEditing (true);
   });
   dvc.View.AddGestureRecognizer(点击);

miguel.de.icaza answered this question on a different thread:
https://stackoverflow.com/a/10864640/1134836.

His solution:

   var tap = new UITapGestureRecognizer ();
   tap.AddTarget (() =>{
       dvc.View.EndEditing (true);
   });
   dvc.View.AddGestureRecognizer (tap);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文