//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - notif
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary* info = [notification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:[info[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0
options:([info[UIKeyboardAnimationCurveUserInfoKey] integerValue]<<16)
animations:^{
_tableFooterLayout.constant = 60 + kbSize.height;
}
completion:nil];
}
- (void)keyboardWillHide:(NSNotification *)notification {
NSDictionary* info = [notification userInfo];
[UIView animateWithDuration:[info[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0
options:([info[UIKeyboardAnimationCurveUserInfoKey] integerValue]<<16)
animations:^{
_tableFooterLayout.constant = 60;
}
completion:nil];
}
IOS 动态获取键盘高度
最新推荐文章于 2024-08-01 04:35:22 发布