码迷,mamicode.com
首页 > 其他好文 > 详细

监听键盘

时间:2016-07-21 19:52:08      阅读:123      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!