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