收起键盘

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

1. 重载 UIViewController 中的 touchesBegin方法, 然后在里面执行 [self.view endEdiiting: YES]; 这样单击UIViewController的任意地方, 就可以收起键盘。

2. 直接执行[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to: nil from: nil forEvent: nil]; 用于在获得当前UIViewController比较困难的时候用。

3. 直接执行 [[[UIApplication sharedApplication] keyWindow] endEditing: YES]

 
原文地址:https://www.cnblogs.com/lisen-lisen/p/4742439.html