//Code from Brett Schumann
-(void) keyboardWillShow:(NSNotification *)note{
NSDictionary* info = [note userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect frame = self.view.frame;
frame.size.height -= kbSize.height;
CGPoint fOrigin = self.nameTextField.frame.origin;
fOrigin.y -= self.scrollView1.contentOffset.y;
fOrigin.y += self.nameTextField.frame.size.height;
if (!CGRectContainsPoint(frame, fOrigin) ) {
CGPoint scrollPoint = CGPointMake(0.0, self.nameTextField.frame.origin.y + self.nameTextField.frame.size.height - frame.size.height);
[self.scrollView1 setContentOffset:scrollPoint animated:YES];
}
}
-(void) keyboardWillHide:(NSNotification *)note{
// get keyboard size and location
[self.scrollView1 setContentOffset:CGPointZero animated:YES];
}
//系统通知 当键盘中英文切换时的事件
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//系统通知 当键盘隐藏时的事件
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];