关于IOS键盘样式(给新手)

1、英文键盘:
  • UIKeyboardTypeAlphabet(Alphabet字母)
  • UIKeyboardTypeASCIICapable
  • UIKeyboardTypeDefault
这三个默认都显示字母表。

2、数字键盘
  • UIKeyboardTypeDecimalPad (Decimal十进制)

3、电子邮箱键盘
  • UIKeyboardTypeEmailAddress

4、没有符号的英文键盘
  • UIKeyboardTypeNamePhonePad

5、没有小数点的数字键盘
  • UIKeyboardTypeNumberPad

6、全键盘的数字键盘
  • UIKeyboardTypeNumbersAndPunctuation

7、带符号的数字键盘
  • UIKeyboardTypePhonePad

8、推特键盘
  • UIKeyboardTypeTwitter

最近做了一个自定义键盘,首先是要知道iOS设备各种键盘的高度,下面就来说一下怎么获取键盘的高度。

  主要是利用键盘弹出时的通知。

  1、首先先随便建一个工程。

  2、在工程的 -(void)viewDidload;函数中添加键盘弹出和隐藏的通知,具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
                                       selector:@selector(keyboardWillShow:)
                                       name:UIKeyboardWillShowNotification
                                       object:nil];
 
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
                                       selector:@selector(keyboardWillHide:)
                                       name:UIKeyboardWillHideNotification
                                       object:nil];

  3、当得到通知时写2个函数,来响应通知 -(void)keyboardWillShow; -(void)keyboardWillHide;

    在这2个函数中可以得到键盘的一些属性,具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
- ( 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
{
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值