隐藏键盘的三种方法

来源:互联网 发布:电脑版数据恢复精灵 编辑:程序博客网 时间:2024/04/30 20:18

第一种通过设置UITextFiledDelegate的方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{    [textField resignFirstResponder];    return YES;}

取消键盘作为第一响应隐藏键盘

第二种通过设置view继承自UIControl 

- (IBAction)backgroundTap:(id)sender {   [text resignFirstResponder];}
取消键盘作为第一响应隐藏键盘

第三种方法通过NSApplication- (BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)sender方法

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)                                           to:nil                                         from:nil                                     forEvent:nil];

取消键盘作为第一响应隐藏键盘(想详细了解可看这篇博客:http://lldong.github.com/blog/2012/11/02/dissmiss-keyboard/)

原创粉丝点击