zoukankan      html  css  js  c++  java
  • iOS 获取键盘高度

    - (void)viewDidLoad {

        [super viewDidLoad];

        //增加监听,当键盘出现或改变时收出消息

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillShow:)

                                                     name:UIKeyboardWillShowNotification

                                                   object:nil];

        

        //增加监听,当键退出时收出消息

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillHide:)

                                                     name:UIKeyboardWillHideNotification

                                                   object:nil];

    }

    - (void)keyboardWillShow:(NSNotification *)aNotification

    {

        //获取键盘的高度

        /*

         iphone 6:

         中文

         2014-12-31 11:16:23.643 Demo[686:41289] 键盘高度是  258

         2014-12-31 11:16:23.644 Demo[686:41289] 键盘宽度是  375

         英文

         2014-12-31 11:55:21.417 Demo[1102:58972] 键盘高度是  216

         2014-12-31 11:55:21.417 Demo[1102:58972] 键盘宽度是  375

         

         iphone  6 plus:

         英文:

         2014-12-31 11:31:14.669 Demo[928:50593] 键盘高度是  226

         2014-12-31 11:31:14.669 Demo[928:50593] 键盘宽度是  414

         中文:

         2015-01-07 09:22:49.438 Demo[622:14908] 键盘高度是  271

         2015-01-07 09:22:49.439 Demo[622:14908] 键盘宽度是  414

         

         iphone 5 :

         2014-12-31 11:19:36.452 Demo[755:43233] 键盘高度是  216

         2014-12-31 11:19:36.452 Demo[755:43233] 键盘宽度是  320

         

         ipad Air:

         2014-12-31 11:28:32.178 Demo[851:48085] 键盘高度是  264

         2014-12-31 11:28:32.178 Demo[851:48085] 键盘宽度是  768

         

         ipad2 :

         2014-12-31 11:33:57.258 Demo[1014:53043] 键盘高度是  264

         2014-12-31 11:33:57.258 Demo[1014:53043] 键盘宽度是  768

         */

        NSDictionary *userInfo = [aNotification userInfo];

        NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

        CGRect keyboardRect = [aValue CGRectValue];

        int height = keyboardRect.size.height;

        int width = keyboardRect.size.width;

        NSLog(@"键盘高度是  %d",height);

        NSLog(@"键盘宽度是  %d",width); 

    }

    //当键退出时调用

    - (void)keyboardWillHide:(NSNotification *)aNotification

    {

    }

  • 相关阅读:
    初级工程师该如何去学习,如何去研发开关电源?
    CentOS-pam认证机制简介
    Linux-密码复杂度限制
    如何写一个简单的webserver(一):最简实现
    MySQL5.6绿色版安装(mysql-5.6.24-winx64.zip)
    Linux忘记roo密码的解决办法
    Linux中的netstat命令详解
    WireShark抓包分析(二)
    Wireshark抓取TCP包分析
    Wireshark 基本介绍和学习 TCP 三次握手
  • 原文地址:https://www.cnblogs.com/-ios/p/5726188.html
Copyright © 2011-2022 走看看