zoukankan      html  css  js  c++  java
  • ios-点击屏幕,隐藏键盘

    ios-点击屏幕,隐藏键盘

    - (void)getFirstRegist{
        //结束键盘编辑
        __weak typeof(self)weakSelf = self;
    
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenKeyBoard)];//注意是UITapGestureRecognizer
        NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];//主队列
    
        //在键盘出现之前,这个函数会被触发(键盘内置的方法,来获取这个通知中的消息)
        [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
            [weakSelf.view addGestureRecognizer:tapGestureRecognizer];
        }];
        [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) {
            [weakSelf.view removeGestureRecognizer:tapGestureRecognizer];
        }];
    }
    
    - (void)hiddenKeyBoard{
        [self.view endEditing:YES];
    }
    
  • 相关阅读:
    MySQL基本命令总结
    B+树
    5.Flask-Migrate
    Tornado入门五
    Django之数据库表的单表查询
    MySQL表完整性约束
    MysQL表相关操作
    MySQL库相关操作
    MySQL创建用户+授权+备份
    公司 邮件 翻译 培训 6 长难句
  • 原文地址:https://www.cnblogs.com/AbeDay/p/5026929.html
Copyright © 2011-2022 走看看