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

     
  • 相关阅读:
    Javascript跨域后台设置拦截
    Hello ReactJS
    Redis 常用监控信息命令总结
    MySQL架构与业务总结图
    MySQL垂直拆分和水平拆分的优缺点和共同点总结
    MySQL实用工具汇总
    MySQL查看数据库表容量大小
    MySQL到底能支持多大的数据量?
    微信小程序wxss的background本地图片问题
    微信小程序中显示与隐藏(hidden)
  • 原文地址:https://www.cnblogs.com/ming1025/p/6138418.html
Copyright © 2011-2022 走看看