• 2016-03-16 键盘的弹出与收起


    1:通知

     [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWasShown:)

                                                     name:UIKeyboardDidShowNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillBeHidden:)

                                                     name:UIKeyboardWillHideNotification object:nil];

    2:方法:

    //键盘显示,调整tableview的高度

    - (void)keyboardWasShown:(NSNotification*)aNotification

    {

       

        //获取通知传递过来的信息

        NSDictionary* info = [aNotification userInfo];

        //获取键盘的size

        CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

        //得到UIEdgeInsets

        UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);

        

       

        

        //设置tableviewUIEdgeInsets

        self.tableView.contentInset = contentInsets;

        self.tableView.scrollIndicatorInsets = contentInsets;

        

        if (isYesName) {

            

            textFieldView.frame = CGRectMake(0, SCREEN_HEIGHT-kbSize.height-60-64, SCREEN_WIDTH, 60);

            

        }

        

    }

     

    //键盘收起,恢复tableviewUIEdgeInsets

    - (void)keyboardWillBeHidden:(NSNotification*)aNotification

    {

        

        UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0,0.0 , 0.0);

        self.tableView.contentInset = contentInsets;

        self.tableView.scrollIndicatorInsets = contentInsets;

        

        

        if (isYesName) {

            

            textFieldView.frame = CGRectMake(0, SCREEN_HEIGHT-64, SCREEN_WIDTH, 60);

            

        }

        

       

    }

  • 相关阅读:
    XMPP资源绑定(Resource Binding)与单台设备登录控制
    解决Eclipse建立Maven项目后无src/main/java资源文件夹的办法
    quartz做集群配置较短的时间间隔会重复执行任务的问题
    同一服务器部署多个tomcat时的端口号修改详情
    Java RSA加密算法生成公钥和私钥
    CSS3动画(重要)
    CSS3 过渡
    CSS3 3D 转换
    CSS3 2D 转换
    CSS3 文本效果(阴影)
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5283339.html
Copyright © 2020-2023  润新知