键盘事件的处理

1     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
2     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
View Code
 1 - (void)keyboardWillShow:(NSNotification *)notification {
 2     NSDictionary *userInfo = [notification userInfo];
 3     NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
 4     CGRect keyboardRect = [aValue CGRectValue];
 5     keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
 6     
 7     CGFloat keyboardTop = keyboardRect.origin.y;
 8     CGRect newTextViewFrame = self.view.bounds;
 9     newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
10 
11     NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
12     NSTimeInterval animationDuration;
13     [animationDurationValue getValue:&animationDuration];
14 
15     [UIView beginAnimations:nil context:NULL];
16     [UIView setAnimationDuration:animationDuration];
17     
18     self.myTableView.frame = newTextViewFrame;
19     
20     [UIView commitAnimations];
21 }
22 
23 
24 - (void)keyboardWillHide:(NSNotification *)notification {
25     
26     NSDictionary* userInfo = [notification userInfo];
27     NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
28     NSTimeInterval animationDuration;
29     [animationDurationValue getValue:&animationDuration];
30     
31     [UIView beginAnimations:nil context:NULL];
32     [UIView setAnimationDuration:animationDuration];
33     
34     self.myTableView.frame = self.view.bounds;
35     
36     [UIView commitAnimations];
37 }

 

转载于:https://www.cnblogs.com/yingkong1987/archive/2012/12/08/2808225.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值