iOS开发一些零碎的小知识(二)
关于收键盘 在viewDidLoad里添加以下代码
self.view.userInteractionEnabled =YES;
UITapGestureRecognizer* guest = [[UITapGestureRecognizeralloc]
initWithTarget:selfaction:@selector(touchView:)];
[self.viewaddGestureRecognizer:guest];
然后在外部定义一个名为touchView的方法
-(void)touchView:(UITapGestureRecognizer*) recognizer{
[self.viewendEditing:YES];
}
加入上述代码后,当点击屏幕的任意地方,手机的键盘就会收起来