美文网首页
收起键盘

收起键盘

作者: toro宇 | 来源:发表于2018-08-01 16:23 被阅读10次

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

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

相关文章

网友评论

      本文标题:收起键盘

      本文链接:https://www.haomeiwen.com/subject/susrvftx.html