我在底部有一个滚动视图,表格视图和文本框,这将触发单击后的键盘显示。 表视图只是滚动视图中的一个子视图,用于显示该照片的一些注释。TableView内容高度在键盘显示后更改
开始时,tableView高度显示正确。但是,在单击该类中的任何textField之后,tableView高度已更改。任何人都有解决方案。
我已经测试了键盘高度。它会影响UITableView的额外高度。 但是我对如何保持键盘显示之前的高度没有任何意见。
请帮忙。
下面是一些代码,
//---when a TextField view begins editing---
-(BOOL) textFieldDidBeginEditing:(UITextField *)textFieldView {
currentTextField = textFieldView;
return YES;
}
-(BOOL) textFieldShouldReturn:(UITextField *) textFieldView {
[textFieldView resignFirstResponder];
return NO;
}
//---when a TextField view is done editing---
-(void) textFieldDidEndEditing:(UITextField *) textFieldView {
currentTextField = nil;
}
//---when the keyboard appears---
-(void) keyboardDidShow:(NSNotification *) notification {
if (keyboardIsShown) return;
NSDictionary* info = [notification userInfo];
//---obtain the size of the keyboard---
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
//---resize the scroll view (with keyboard)---
CGRect viewFrame = [v_comment_editor frame];
viewFrame.size.height -= keyboardSize.height;
v_comment_editor.frame = viewFrame;
//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[v_comment_editor scrollRectToVisible:textFieldRect animated:YES];
keyboardIsShown = YES;
}
//---when the keyboard disappears---
-(void) keyboardDidHide:(NSNotification *) notification {
NSDictionary* info = [notification userInfo];
//---obtain the size of the keyboard---
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
//---resize the scroll view back to the original size (without keyboard)---
CGRect viewFrame = [v_comment_editor frame];
viewFrame.size.height += keyboardSize.height;
v_comment_editor.frame = viewFrame;
keyboardIsShown = NO;
}
-(void) viewWillDisappear:(BOOL)animated {
//---removes the notifications for keyboard---
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}