Can I dismiss the iPhone keyboard by touching the background of DialogViewController (MonoTouch.Dialog)? [duplicate]

ε祈祈猫儿з 提交于 2019-12-30 04:32:07

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/3463778/can-i-dismiss-the-iphone-keyboard-by-touching-the-background-of-dialogviewcontro

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