国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

獲取iOS設(shè)備鍵盤高度

2019-11-14 19:39:19
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  最近做了一個(gè)自定義鍵盤,首先是要知道iOS設(shè)備各種鍵盤的高度,下面就來(lái)說(shuō)一下怎么獲取鍵盤的高度。

  主要是利用鍵盤彈出時(shí)的通知。

  1、首先先隨便建一個(gè)工程。

  2、在工程的 -(void)viewDidload;函數(shù)中添加鍵盤彈出和隱藏的通知,具體代碼如下:

 1       //增加監(jiān)聽,當(dāng)鍵盤出現(xiàn)或改變時(shí)收出消息 2       [[NSNotificationCenter defaultCenter] addObserver:self 3                                             selector:@selector(keyboardWillShow:) 4                                             name:UIKeyboardWillShowNotification 5                                             object:nil]; 6  7       //增加監(jiān)聽,當(dāng)鍵退出時(shí)收出消息 8       [[NSNotificationCenter defaultCenter] addObserver:self 9                                             selector:@selector(keyboardWillHide:)10                                             name:UIKeyboardWillHideNotification11                                             object:nil];

  3、當(dāng)?shù)玫酵ㄖ獣r(shí)寫2個(gè)函數(shù),來(lái)響應(yīng)通知 -(void)keyboardWillShow; -(void)keyboardWillHide;

    在這2個(gè)函數(shù)中可以得到鍵盤的一些屬性,具體代碼如下:

 1 - (void)keyboardWillShow:(NSNotification *)aNotification 2 { 3     //獲取鍵盤的高度 4     /* 5      iphone 6: 6      中文 7      2014-12-31 11:16:23.643 Demo[686:41289] 鍵盤高度是  258 8      2014-12-31 11:16:23.644 Demo[686:41289] 鍵盤寬度是  375 9      英文10      2014-12-31 11:55:21.417 Demo[1102:58972] 鍵盤高度是  21611      2014-12-31 11:55:21.417 Demo[1102:58972] 鍵盤寬度是  37512      13      iphone  6 plus:14      英文:15      2014-12-31 11:31:14.669 Demo[928:50593] 鍵盤高度是  22616      2014-12-31 11:31:14.669 Demo[928:50593] 鍵盤寬度是  41417      中文:18      2015-01-07 09:22:49.438 Demo[622:14908] 鍵盤高度是  27119      2015-01-07 09:22:49.439 Demo[622:14908] 鍵盤寬度是  41420      21      iphone 5 :22      2014-12-31 11:19:36.452 Demo[755:43233] 鍵盤高度是  21623      2014-12-31 11:19:36.452 Demo[755:43233] 鍵盤寬度是  32024      25      ipad Air:26      2014-12-31 11:28:32.178 Demo[851:48085] 鍵盤高度是  26427      2014-12-31 11:28:32.178 Demo[851:48085] 鍵盤寬度是  76828      29      ipad2 :30      2014-12-31 11:33:57.258 Demo[1014:53043] 鍵盤高度是  26431      2014-12-31 11:33:57.258 Demo[1014:53043] 鍵盤寬度是  76832      */33     NSDictionary *userInfo = [aNotification userInfo];34     NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];35     CGRect keyboardRect = [aValue CGRectValue];36     int height = keyboardRect.size.height;37     int width = keyboardRect.size.width;38     NSLog(@"鍵盤高度是  %d",height);39     NSLog(@"鍵盤寬度是  %d",width);40 }41 42 //當(dāng)鍵退出時(shí)調(diào)用43 - (void)keyboardWillHide:(NSNotification *)aNotification44 {45 }

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 商都县| 南澳县| 穆棱市| 丹凤县| 平安县| 昭苏县| 闵行区| 潮安县| 修文县| 五峰| 内丘县| 双流县| 玉林市| 德格县| 从化市| 泉州市| 南开区| 张家界市| 郴州市| 清涧县| 乐业县| 镇坪县| 合水县| 即墨市| 汉阴县| 蒙自县| 山阳县| 紫金县| 西昌市| 繁昌县| 辽阳县| 苍南县| 葫芦岛市| 江都市| 孙吴县| 永清县| 澳门| 惠州市| 浦城县| 古丈县| 泰安市|