IOS开发 循环遍历隐藏键盘

在顶级viewControl中设置


- (void)viewDidLoad {

    [super viewDidLoad];


    //设置全局的触摸空白位置,隐藏键盘功能

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];

    //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES

    tapGestureRecognizer.cancelsTouchesInView = NO;

    //将触摸事件添加到当前view

    [self.view addGestureRecognizer:tapGestureRecognizer];

}


-(void)keyboardHide:(UITapGestureRecognizer*)tap{

    [self dumpViewHideKeyboard:self.view];

}


- (void)dumpViewHideKeyboard:(UIView *)aView

{

    for (id obj in aView.subviews) {

        NSLog(@"obj class: %@",[obj class]);

        if ([obj isKindOfClass:[UITextField class]]) {

            UITextField* theTextField = (UITextField*)obj;

            [theTextField resignFirstResponder];

        }

        else if ([obj isKindOfClass:[UITextView class]]){

            UITextView* theTextView = (UITextView*)obj;

            [theTextView resignFirstResponder];

        }

        else if ([obj isKindOfClass:[UIView class]]){

            [self dumpViewHideKeyboard:obj];

        }

    }

}

阅读更多
文章标签: IOS ios开发
个人分类: IOS
上一篇iOS开发-21UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解
下一篇根据key查找对应内容:
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭