OC 在任意页面,隐藏其他页面的键盘

一、当前viewController隐藏本页面的键盘

    很容易。直接调用 [textfield resignFirstResponder]即可。

二、目前遇到一个需求

     ControllerA出来时候,隐藏当前top 任意view的键盘。那么可以使用这个

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
这是有根据的,OC sdk中有一个UIView的类别,就是endEditing。可以参考UITextField.h的头文件

@interface UIView (UITextField)
- (BOOL)endEditing:(BOOL)force;    // use to make the view or any subview that is the first responder resign (optionally force)
@end

三、如果不方便获取当前view

    可以使用该方法

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponser) to:nil from:nil forEvent:nil];


你可能感兴趣的:(隐藏键盘,任意页面)