当我只是触摸UITextField以外的任何地方时,如何解除键盘? [英] how can I dismiss keyboard when I will just touch anywhere except UITextField?

查看:188
本文介绍了当我只是触摸UITextField以外的任何地方时,如何解除键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello
我的应用程序中有两个UITextFields,当我只是触摸UITextFields以外的任何地方时想要解除键盘
我该怎么办?

Hello I have two UITextFields in my application, and want to dismiss the keyboard when I just touch anywhere except the UITextFields how can I do this?

推荐答案

为此目的使用tochesBegin方法

use tochesBegin method for this purpose

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

  [yourFirstTextField resignFirstResponder];
  [yourSecondTextField resignFirstResponder];
}

你不需要任何其他东西。当你触摸任何地方时,两者都是textField resign无需知道哪一个有焦点。当你触摸textField然后textField自己打开键盘。

You do not need any thing else.When you touch anywhere on view then both textField resign no need to to know which one having focus.and when you touch textField then textField open keyboard by own.

这篇关于当我只是触摸UITextField以外的任何地方时,如何解除键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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