【发布时间】:2014-11-20 14:03:24
【问题描述】:
我正在开发一个聊天应用程序,它在视图上放置了 textview 和其他按钮。设置预测时,iOS8 键盘出现问题。 当预测关闭时,它工作正常,但它设置在我的视图中,其中放置了 textview 和其他按钮。
我在 viewDidLoad 中为 KeyboardWillShow 和 KeyboardWillHide 添加了 NSNotification。
viewDummy 是添加了 textview 和其他按钮的视图
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary* info = [notification userInfo];
CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.2f animations:^{
CGRect frame = viewDummy.frame;
frame.origin.y -= kbSize.height;
viewDummy.frame = frame;
frame = bubbleTable.frame;
frame.size.height -= kbSize.height;
bubbleTable.frame = frame;
}];
}
-(void) keyboardWillHide:(NSNotification *)note{
NSDictionary* info = [note userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.2f animations:^{
CGRect frame = viewDummy.frame;
frame.origin.y += kbSize.height;
viewDummy.frame = frame;
frame = bubbleTable.frame;
frame.size.height += kbSize.height;
bubbleTable.frame = frame;
}];
}
【问题讨论】:
-
如果您关闭键盘并再次显示,视图是否放错了位置?
UIKeyboardWillChangeFrameNotification和UIKeyboardDidChangeFrameNotification在打开/关闭预测输入时会发布通知。注册这些通知可能会对您有所帮助。
标签: ios objective-c xcode