• 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

     
  • 相关阅读:
    Winform/WPF实例中的相互操作
    如何在WPF中调用Winform控件
    实现页面的GZip或Deflate压缩。
    奇怪的JS 缺少函数问题
    JavaScript可以根据浏览器类别决定是否注册函数?
    readonly与const
    如何读取系统字体、颜色、大小?
    Javascript实现div的toggle效果小记及其它。
    ACCESS SELECT TOP N的问题
    如何将Dictionary绑定到Repeater?
  • 原文地址:https://www.cnblogs.com/ming1025/p/6138418.html
Copyright © 2020-2023  润新知