使用UIKeyboard预测打开和关闭来管理视图位置 [英] Manage view position with UIKeyboard prediction on and off
本文介绍了使用UIKeyboard预测打开和关闭来管理视图位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在显示键盘时向上移动视图,而在像消息一样隐藏键盘时向下移动视图.我能够实现,但是我隐藏了预测,那里有一些空白.
I want to move the view up when the keyboard is shown and down when keyboard is hidden like in message. I am able to achieve it, but the i hide the prediction there is some blank space.
我正在使用" UIKeyboardWillShowNotification "和" UIKeyboardWillHideNotification "来处理键盘的移动
I am handling the movement of keyboard with "UIKeyboardWillShowNotification" and "UIKeyboardWillHideNotification"
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - keyboard movements
- (void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
self.view.frame = f;
}];
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.view.frame = f;
}];
}
我想像在消息应用程序中一样处理视图的移动.
I want to handle the movement of view like it happens in messages app.
推荐答案
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
替换为下一行
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
这篇关于使用UIKeyboard预测打开和关闭来管理视图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文