您的位置:首页 > 移动开发 > IOS开发

iOS 隐藏键盘的几种常见方法

2016-02-27 18:10 417 查看
1.设置return key,然后为Did End On Exit事件添加响应方法,并在方法内添加代码:[self.textfieldName resignFirstResponder]。

2.将背景view设置为UIControl类,然后为Touch Down事件添加响应方法,并在方法内添加代码:[self.textfieldName resignFirstResponder]。

3.重载- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event方法,并在方法内添加代码:[self.textfieldName resignFirstResponder] 或者 [self.view endEditing:YES]。

4.直接执行[[UIApplication sharedApplication]sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 用于在获得当前UIViewController比较困难的时候。

5.直接执行[[[UIApplication sharedApplication]keyWindow]endEditing:YES]。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: