1.今天在做项目的时候,偶然发现在scrollview 上面放置textField,然后通过常规的方法来消退键盘,怎么也消退不了,即使设置
_scrollView.userInteractionEnabled =YES;也还是不行,于是在一篇blog上面找到一个方法,通过给scrollView添加tap 手势,可以达到消退键盘的目的。下面上代码:
2.下面总结俩种常规的消退键盘方法
①: - (void)touchesBegan:(NSSet<UITouch *>*)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
<span style="font-size:14px;"> ②:</span>-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
③: 直接执行[[UIApplicaton sharedApplication] sendAcion;@selector(resignFirstResopnder) to:nil from:nil forEvent:nil];
用于在获得当前UIViewController比较困难的时候使用。
④: 直接执行:[[[UIApplication sharedApplication] keyWindow] endEditing:YES]