1. 代理
UITextFieldDelegate
2. 设置代理
textfield.delegate = self;
3. 代理事件处理
#pragma mark - textfiled代理 -(void)textFieldDidEndEditing:(UITextField *)textField{ [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; }