How to dismiss number pad keyboard by tapping anywhere

后端 未结 15 2180
梦如初夏
梦如初夏 2020-12-04 17:53

I\'d like to know the simplest code to dismiss the number pad keyboard when tapping anywhere outside the number pad. It\'s a simple application to input a number inside a te

15条回答
  •  情话喂你
    2020-12-04 18:08

    You must use UITapGestureRecognizer to achieve this.

    UITapGestureRecognizer *tapToDismiss = [[UITapGestureRecognizer alloc]initWithTarget: self action: @selector (dismissNumberKeyBoard:)];
    

    Then in your dismissNumberKeyboard method,

    -(Void)dismissNumberKeyboard : (id)sender {
    
       [yourTextField resignFirstResponder];
    
    }
    

    Happy coding!

提交回复
热议问题