码迷,mamicode.com
首页 > 移动开发 > 详细

ios键盘监听

时间:2016-01-28 10:59:18      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

1         // 监听键盘
2         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowAction:) name:UIKeyboardWillShowNotification object:nil];
3         
4         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideAction:) name:UIKeyboardWillHideNotification object:nil];

 

 

 1 #pragma mark - 键盘处理
 2 
 3 /**
 4  *  键盘即将隐藏
 5  */
 6 - (void)keyboardWillHideAction:(NSNotification *)note
 7 {
 8     
 9     // 1.键盘弹出需要的时间
10     CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
11     
12     // 2.动画
13     [UIView animateWithDuration:duration animations:^{
14         self.view.transform = CGAffineTransformIdentity;
15     }];
16 }
17 
18 /**
19  *  键盘即将弹出
20  */
21 - (void)keyboardWillShowAction:(NSNotification *)note
22 {
23     
24     // 1.键盘弹出需要的时间
25     CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
26     
27     // 2.动画
28     [UIView animateWithDuration:duration animations:^{
29         // 取出键盘高度
30         CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
31         CGFloat keyboardH = keyboardF.size.height - 40;
32         if (ThreeInch) {
33             self.view.transform = CGAffineTransformMakeTranslation(0, - keyboardH);
34         } else {
35             self.view.transform = CGAffineTransformMakeTranslation(0, - 50);
36         }
37     }];
38 }

 

ios键盘监听

标签:

原文地址:http://www.cnblogs.com/PJHome/p/5165384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!