5 ways Disappear Keyboard
1,輸入完后,點擊鍵盤中的return ,使??消失
.h文件interface那一行后面添加<UITextFieldDelegate>
.m文件中添加 - (void)textFieldShouldReturn:(UITestField *)textField
{
[textField resignFirstResponser];
return YES;
}
拖拽UITextField控件關聯viewController中的delegate
2,事件響應的調用
控件進行拖拽兩次,一次是做正常的outlet,另一次選擇Action,Event為Did End On Exit,
然后在.m文件中實現方法 [_mtf resignFirstResponser];
3,通過改變view 的class類型為UIControl,拖拽textfield創建outlet,拖拽control創建IBAction,選擇Action,Event為 touch Up Inside,
在.m文件中實現方法 [_mtf resignFirstResponser];
4,巧用UIButton
拖拽控件,在button的點擊方法中添加 [_mtf resignFirstResponser];
5,點擊空白處,讓鍵盤消失
.m文件中直接添加函數
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.window endEditing:YES];
}