1、點擊Return按扭時收起鍵盤变过。注意:需要遵從UITextFieldDelegate協(xié)議吏够,并設(shè)置好代理
-(BOOL)textFieldShouldReturn:(UITextField*)textField{????
? ? return[textField?resignFirstResponder];
}
或者
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
????return ?[textField?endEditing:YES];
}
或者(這里的View必須是繼承于UIControl)
-?(BOOL)textFieldShouldReturn:(UITextField*)textField{
? ? return ?[self.view?endEditing:YES];
}
或者
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
????return ?[[[UIApplication?sharedApplication]keyWindow]endEditing:YES];
}
2抡草、點擊背景View收起鍵盤
-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{
//以上4種收起方式中的任何一種
}