iOS中的键盘处理
  • UIKeyboardWillShowNotification;
  • UIKeyboardDidShowNotification;
  • UIKeyboardWillHideNotification;
  • UIKeyboardDidHideNotification;

iOS5.0以后

  • UIKeyboardWillChangeFrameNotification
  • UIKeyboardDidChangeFrameNotification

ChangeFrame 可用于监听键盘的显示和隐藏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

- (void)viewDidLoad {
[super viewDidLoad];

// 发出通知监听键盘的显示或隐藏
/*
* UIKeyboardWillShowNotification;
* UIKeyboardDidShowNotification;
* UIKeyboardWillHideNotification;
* UIKeyboardDidHideNotification;
* UIKeyboardWillChangeFrameNotification
* UIKeyboardDidChangeFrameNotification
*/
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)keyboardWillChangeFrame:(NSNotification *)note
{
// 这里我们通过 note.userInfo 这个字典来取出对应的 key 进行操作
NSLog(@"%@", note);
}
1
2
3
4
5
6
7
8
9
10
11

NSConcreteNotification 0x7fed62569a50 {name = UIKeyboardWillChangeFrameNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {414, 271}}"; // 键盘尺寸
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {207, 871.5}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {207, 600.5}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 736}, {414, 271}}"; // 弹出前的 frame
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 465}, {414, 271}}"; // 弹出后的 frame
UIKeyboardIsLocalUserInfoKey = 1;
}}
文章作者: Ammar
文章链接: http://lizhaoloveit.cn/2014/04/10/iOS%E4%B8%AD%E7%9A%84%E9%94%AE%E7%9B%98%E5%A4%84%E7%90%86/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ammar's Blog
打赏
  • 微信
  • 支付宝

评论