// 取消页面自动上移
[IQKeyboardManager sharedManager].enable = NO; // 有第三方IQKeyboardManager的项目
#1.注册监听
[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyBoardWillShow:)name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyBoardWillHide:)name:UIKeyboardWillHideNotification object:nil];
#2.根据监听获取键盘的高度
-(void)keyBoardWillShow:(NSNotification*)note{
// 获取用户信息
NSDictionary*userInfo=[NSDictionary dictionaryWithDictionary:note.userInfo];
// 获取键盘高度
CGRect keyBoardBounds=[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
CGFloat keyBoardHeight=keyBoardBounds.size.height;
// 获取键盘动画时间
CGFloat animationTime=[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]floatValue];
}
//键盘收起-(void)keyBoardWillHide:(NSNotification*)note{}
#3.记得移除监听!
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
网友评论