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
    {
        //获取键盘的高度
        NSDictionary *userInfo = [aNotification userInfo];
        NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardRect = [aValue CGRectValue];
       int height = keyboardRect.size.height;
    }
    
    //当键退出时调用
    - (void)keyboardWillHide:(NSNotification *)aNotification
    {

    }

    高度值其实就只有两种类型,一个是Default一个是Number

    ①以下几种键盘类型几乎一样,键盘高度也是一样的

    UIKeyboardTypeAlphabet
    UIKeyboardTypeASCIICapable
    UIKeyboardTypeDefault
    UIKeyboardTypeEmailAddress
    UIKeyboardTypeNamePhonePad
    UIKeyboardTypeNumbersAndPunctuation(数字和标点符号)
    UIKeyboardTypeTwitter
    UIKeyboardTypeURL
    UIKeyboardTypeWebSearch

    5.5吋271

    4.7吋258

    4.0吋253

    ②以下几种键盘为数字类型的键盘,键盘高度也是一样的

    UIKeyboardTypeDecimalPad(带小数点的数字键盘)
    UIKeyboardTypeNumberPad(纯数字键盘)
    UIKeyboardTypePhonePad(带*+#,;的数字键盘)

    5.5吋226

    4.7吋216

    4.0吋216

     
  • 相关阅读:
    电子商务测试点总结
    pc 端 测试点总结
    web测试点总结
    Monkey脚本API
    Git 命令
    配置samba的流程
    scrapy使用指南
    链接
    顺序表总结
    python数据类型——字符串类型
  • 原文地址:https://www.cnblogs.com/ming1025/p/6138418.html
Copyright © 2011-2022 走看看