当键盘出现时尝试向上移动滚动视图时遇到问题。滚动视图在 ios7 中向上移动,但在 ios6 中没有,并且键盘上方有额外的空白区域隐藏了屏幕上的控件
我的代码:
- (void)viewWillAppear:(BOOL)animated
{
[super viewDidAppear:animated];
keyboardIsShown = NO;
[super viewWillAppear:animated];
[[self view] endEditing:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:self.view.window];
}
- (void)keyboardWillShow:(NSNotification *)n
{
if (keyboardIsShown) {
return;
}
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// resize the noteView
CGRect viewFrame = self.scrollView.frame;
viewFrame.size.height -= (keyboardSize.height - kTabBarHeight);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
// The kKeyboardAnimationDuration I am using is 0.3
[UIView setAnimationDuration:kKeyboardAnimationDuration];
[self.scrollView setFrame:viewFrame];
[UIView commitAnimations];
scrollView.contentSize = formView.frame.size;
keyboardIsShown = YES;
}
这里有什么问题。请帮忙