第一种:
创建一个不可见的button,将其放在其他所有元素后面,然后在该button的触发事件中写resignFirstResponder
具体分四步:
1、拖一个round rect button到视图窗口,调整大小使其占据整个屏幕。
2、从xcode菜单中选择send to back,使该button置于后面。
3、将该button的类型改为custom,使其失去round rect button的特性。
4、写一个backgroundClick方法,使其作为该button的响应函数。
4、写一个backgroundClick方法,使其作为该button的响应函数。
第二种(更高效的一种方法):
实现touchesBegan方法来隐藏键盘:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[textField resignFirstResponder];
self.label.text = textField.text; //do some other things.
}