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];
    }
    
  • 相关阅读:
    2. 开关电源.电感
    1. 开关电源.引子
    资源介绍
    3. EMC EMS EMI
    2. 基于MCU应用的EMC指南
    1. 内部管脚电路
    9.150 Predefined macros
    海康安防平台
    Redis常见配置
    利用python检测单词的相似度
  • 原文地址:https://www.cnblogs.com/AbeDay/p/5026929.html
Copyright © 2011-2022 走看看