为什么我的TableView会向上移动?

时间:2011-08-06 16:24:28

标签: iphone uiscrollview keyboard

TableViewCell gets shifted up when keyboardIsShown

我有一个在显示键盘时调用的方法。它正在研究其他观点。不知怎的,TableView向上移动了。

-(void) keyboardDidShow:(NSNotification *) notification {
// -- return if keyboard is still shown
MyManager *sharedManager = [MyManager sharedManager];
if ([sharedManager.keyboardIsShown isEqualToString:@"YES"]) return;
NSDictionary* info = [notification userInfo];

//---obtain the size of the keyboard---
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil];

//---resize the scroll view (with keyboard)---
CGRect viewFrame = [scrollView frame];
viewFrame.size.height -= keyboardRect.size.height;
scrollView.frame = viewFrame;

//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
sharedManager.keyboardIsShown = @"YES";

}

1 个答案:

答案 0 :(得分:4)

设置myTableView.autoresizingMask = 0;就可以了。