我在底部有一個滾動視圖,表格視圖和文本框,這將觸發單擊後的鍵盤顯示。 表視圖只是滾動視圖中的一個子視圖,用於顯示該照片的一些註釋。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];
}