现在我正在尝试编写一个函数来在屏幕上出现键盘时向上移动框架。我开始使用 NSNNotificationCenter。我的代码工作但不正确。当键盘出现时,我的 formView 正在向上移动,但是当我开始在 formView 中编辑下一个 textField 时,formView 再次向上移动。我的代码有什么问题?谢谢。
- (void)keyboardWillShow:(NSNotification *) aNotification {
NSDictionary *userInfo = [aNotification userInfo];
CGRect frame = self.formView.frame;
frame.origin.y -= 170;
NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration;
[animationDurationValue getValue:&animationDuration];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
formView.frame = frame;
[UIView commitAnimations];
}