zoukankan      html  css  js  c++  java
  • 关闭和打开键盘的通知

    在ViewController.m中添加代码:

    -(void)viewWillAppear:(BOOL)animated
    {
        // 注册键盘出现通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
        // 注册键盘隐藏通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
        [super viewWillAppear:animated];
    }
    
    -(void)viewWillDisappear:(BOOL)animated
    {
        // 解除键盘出现通知
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
        // 解除键盘隐藏通知
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
        [super viewWillDisappear:animated];
    }
    
    -(void)keyboardDidShow: (NSNotification *)notif {
        NSLog(@"键盘打开");
    }
    
    -(void)keyboardDidHide: (NSNotification *)notif {
        NSLog(@"键盘关闭”);
    


  • 相关阅读:
    课后作业之找水王
    SCRUM第二阶段第十天
    第九周总结
    冲刺一3
    用户项目
    预会热词统计
    冲刺一2
    冲刺一(一阶)1
    第八周总结
    小组合作
  • 原文地址:https://www.cnblogs.com/zhangyaoqi/p/4591607.html
Copyright © 2011-2022 走看看