MonoTouch.Dialog:通过触摸 DialogViewController 中的任意位置来关闭键盘 [英] MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController

查看:32
本文介绍了MonoTouch.Dialog:通过触摸 DialogViewController 中的任意位置来关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:有两个类似的 SO 问题 (1) (2),但他们都没有提供答案.

TL;DR:如何通过让用户触摸视图中的任何空白区域来关闭 MonoTouch.Dialog 中的键盘?

我正在使用 MonoTouch.Dialog 和一个 UITabBarController 编写一个应用程序.我的标签之一是设置"...

I'm writing an app using MonoTouch.Dialog and a UITabBarController. One of my tabs is "Settings"...

当用户开始打字时,键盘挡住了tabbar...

When the user starts typing, the keyboard obstructs the tabbar...

使用 MonoTouch.Dialog,关闭键盘的唯一方法是转到最后一个字段并按返回"键.考虑到用户在键盘消失之前无法按下任何选项卡这一事实,我想要一种更好的方法来做到这一点.即,如果用户点击屏幕上的任何其他地方,则关闭.

Using MonoTouch.Dialog, the only way to dismiss the keyboard is to go to the last field and press the "return" key. Considering the fact that the user cannot press any tab until the keyboard is gone, I would like a better way to do it. Namely, to dismiss if the user taps anywhere else on the screen.

如果没有 MonoTouch.Dialog,这很简单:只需覆盖 TouchesBegan 并调用 EndEditing.但这不适用于 MT.D.我试过子类化 DialogViewController 并在那里覆盖 TouchesBegan,但它不起作用.我现在不知所措.

Without MonoTouch.Dialog, it's a snap: simply override TouchesBegan and call EndEditing. But this doesn't work with MT.D. I've tried subclassing DialogViewController and overriding TouchesBegan there, but it doesn't work. I'm currently at a loss.

或者,我想知道,我是否最好放弃标签栏,以便我可以使用顶部带有返回"按钮的 UINavigationController,该按钮不会被键盘隐藏?

Or, I wonder, would I be better off ditching the tabbar so I can use a UINavigationController with a "Back" button on top, which won't be hidden by the keyboard?

推荐答案

我建议您使用不会干扰 TableView 事件处理程序的点击手势识别器:

I suggest you use a tap gesture recognizer that will not cause interference with the TableView event handlers:

var tap = new UITapGestureRecognizer ();
tap.AddTarget (() => dvc.View.EndEditing (true));
dvc.View.AddGestureRecognizer (tap);
tap.CancelsTouchesInView = false;

这篇关于MonoTouch.Dialog:通过触摸 DialogViewController 中的任意位置来关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆