标签:
方法一:点击屏幕背景,键盘下落
//触摸背景键盘下落 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; }
方法二:点击return键键盘下落
[_textfield addTarget:self action:@selector(keyboarddissappear) forControlEvents:UIControlEventEditingDidEndOnExit]; //点击事件可以为空 -(void)keyboarddissappear { }
方法三:点击其他控件,textfield失去第一响应,如:添加一个按钮
//创建按钮 UIButton *button=[UIButton buttonWithType:UIButtonTypeContactAdd]; button.frame=CGRectMake(0, 0, 100, 50); [button addTarget:self action:@selector(keyboarddismiss) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } //点击事件,使键盘失去第一响应 -(void)keyboarddismiss { [_textfield resignFirstResponder]; }
标签:
原文地址:http://www.cnblogs.com/kyuubee/p/4808178.html