我正在开发一个聊天应用程序,其中我用UITableView编写了UIView,在UIView的底部有另一个UIView(比如userInputView),它有一个UITextField和一个作为子视图添加的UIButton。
当用户轻击UITextField键盘时,此UIView(userInputView)会向上移动,以便使用UIKeyboardDidChangeFrameNotification根据键盘高度调整自身。
当我点击“发送”按钮时,我将UITextField的文本设置为空。
这在iOS 7之前运行良好,但在iOS 8中,当我更改UITextField的文本时,userInputView视图隐藏在预测文本视图下。当我最小化预测文本视图时,userInputView会再次显示,但当我最大化预测文本视图时,它会再次隐藏。
所有这些都是在我点击send按钮时尝试更改UITextField文本时发生的。如果我不更改UITextField的文本,那么它工作得很好。
请帮助我如何在iOS8中解决此问题。即使我隐藏了预测文本视图,userInputView也会隐藏起来,再也不会显示了。
关于Gurpreet
发布于 2014-10-18 18:13:31
我有和你一样的问题,但在检查了键盘通知enums.So后,我使用了UIKeyboardDidChangeFrameNotification或UIKeyboardWillChangeFrameNotification,因为它们会告诉你当键盘在视图中或用户打开或关闭设置时,当预测文本栏上升或下降时,键盘边框的变化。下面是运行良好的代码。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardFrameDidChange:)
name:UIKeyboardDidChangeFrameNotification object:nil];
-(void)keyboardFrameDidChange:(NSNotification*)notification{
NSDictionary* info = [notification userInfo];
CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
if (kKeyBoardFrame.size.height == HEIGHT_OF_KEYBOARD) {
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height+32, 320, viewCommentText.frame.size.height)];
}else if (kKeyBoardFrame.size.height == 224){
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height+18, 320, viewCommentText.frame.size.height)];
}else{
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height-viewCommentText.frame.size.height, 320, viewCommentText.frame.size.height)];
}
}当你离开你的视图时,还要删除观察者
#pragma mark Device constrols Constant
#define HEIGHT_OF_STATUS_BAR 20
#define HEIGHT_OF_TOOLBAR 44
#define HEIGHT_OF_TABLE_CELL 44
#define HEIGHT_OF_TAB_BAR 49
#define HEIGHT_OF_SEARCH_BAR 44
#define HEIGHT_OF_NAVIGATION_BAR 44
#define HEIGHT_OF_TEXTFIELD 31
#define HEIGHT_OF_PICKER 216
#define HEIGHT_OF_KEYBOARD 216
#define HEIGHT_OF_SEGMENTED_CONTROL 43
#define HEIGHT_OF_SEGMENTED_CONTROL_BAR 29
#define HEIGHT_OF_SEGMENTED_CONTROL_BEZELED 40
#define HEIGHT_OF_SWITCH 27
#define HEIGHT_OF_SLIDER 22
#define HEIGHT_OF_PROGRESS_BAR 9
#define HEIGHT_OF_PAGE_CONTROL 36
#define HEIGHT_OF_BUTTON 37https://stackoverflow.com/questions/26210154
复制相似问题