首页 > 其他 > 详细

监听键盘

时间:2016-07-21 19:49:38      阅读:116      评论:0      收藏:0      [点我收藏+]
 1 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
 2 
 3 - (void)dealloc
 4 {
 5     [[NSNotificationCenter defaultCenter] removeObserver:self];
 6     
 7     self.topic.top_cmt = self.savedTopCmt;
 8     self.topic.cellHeight = 0;
 9 }
10 
11 - (void)keyboardWillChangeFrame:(NSNotification *)note
12 {
13     // 修改约束
14     CGFloat keyboardY = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
15     CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
16     self.bottomMargin.constant = screenH - keyboardY;
17     
18     // 执行动画
19     CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
20     [UIView animateWithDuration:duration animations:^{
21         [self.view layoutIfNeeded];
22     }];
23 }

 

监听键盘

原文:http://www.cnblogs.com/mkai/p/5692795.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!