Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog? [duplicate]

北战南征 提交于 2019-12-23 04:47:23

问题


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

I noticed that when touching outside of the table cell (which I suppose is the 'section'), the touchesBegan method does not get called so I can't call EndEditing or ResignFirstReponder.

I am creating a multiline entry element; because of this, the return key goes to a new line instead of "returning". This is the intended behavior. However, I have no way to dismiss the keyboard then.

I noticed in the settings for menu on the iPhone (General->Keyboard->Shortcuts) or when entering credentials, that touching in the outer area does not resign the responder. Does this mean that this is a limitation of iOS as a whole (or Apple just didn't see fit in these instances)?

Is there anyway to do this?

There is, what I gather, an identical question here but no one came up with a valid answer:
Can I dismiss the iPhone keyboard by touching the background of DialogViewController (MonoTouch.Dialog)?

Maybe in a year and a half someone has solved it?


回答1:


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);



回答2:


I think you have 2 options:

  • Put a "Done" button somewhere
  • Hook up the touch event on the background of your view to dismiss

I think the first option is better, since it is what Safari does.

You can attach a toolbar to the top of the keyboard to simulate what Safari does with InputAccessoryView. Here is an example of doing this in Obj-C (should be easy to port): http://gabriel-tips.blogspot.com/2011/05/input-accessory-view-how-to-add-extra.html

It may not work for your layout, however, if screen real estate is tight. Go with option #2 in that case.



来源:https://stackoverflow.com/questions/10097490/can-the-keyboard-be-dismissed-by-touching-outside-of-the-cell-in-monotouch-dialo

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