iOS中键盘的收起

在UIViewController中收起键盘,除了调用相应控件的resignFirstResponder方法之外,还有另外三种方法:

  1. 重载UIViewController中的touchesBegin方法,然后在里面执行[self.view endEditing:YES];,这样单击UIViewController的任意地方,就可以收起键盘;
  2. 直接执行[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];,用于在获得当前UIViewController比较困难的时候用。
  3. 直接执行[[[UIApplication sharedApplication] keyWindow] endEditing:YES]

参考唐巧大神的《iOS开发进阶》。

posted @ 2015-04-15 11:51  脸大皮厚歌  阅读(152)  评论(0编辑  收藏  举报