how can I dismiss keyboard when I will just touch anywhere except UITextField?

后端 未结 10 2007
独厮守ぢ
独厮守ぢ 2021-02-19 11:12

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?

10条回答
  •  攒了一身酷
    2021-02-19 11:54

    use tochesBegin method for this purpose

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
      [yourFirstTextField resignFirstResponder];
      [yourSecondTextField resignFirstResponder];
    }
    

    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.

提交回复
热议问题