您的位置:首页 > 移动开发 > IOS开发

监听键盘高度

2015-09-26 14:00 281 查看
在遇到有输入的情况下。由于现在键盘的高度是动态变化的。中文输入与英文输入时高度不同。所以输入框的位置也要做出相应的变化


添加监听事件:

//增加监听,当键盘出现或改变时收出消息    [[NSNotificationCenter defaultCenter] addObserver:self                                             selector:@selector(keyboardWillShow:)                                                 name:UIKeyboardWillShowNotification//这个是带系统动画的                                 //UIKeyboardDidShowNotification 键盘出来后再出现,不带动画                                              object:nil];        //增加监听,当键退出时收出消息    [[NSNotificationCenter defaultCenter] addObserver:self                                             selector:@selector(keyboardWillHide:)                                                 name:UIKeyboardWillHideNotification                                               object:nil];        

//当键盘出现或改变时调用- (void)keyboardWillShow:(NSNotification *)aNotification{    //获取键盘的高度    NSDictionary *userInfo = [aNotification userInfo];    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];    CGRect keyboardRect = [aValue CGRectValue];    int height = keyboardRect.size.height;}
//当键退出时调用- (void)keyboardWillHide:(NSNotification *)aNotification{    }







                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios