现在,我正在尝试写一个函数,当键盘出现在屏幕上时,将帧上移。我开始使用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];
}发布于 2012-04-04 17:53:59
当键盘消失时,您应该再次将170像素(或Mike建议的任何计算方法)添加到视图的origin.y中。当你点击另一个文本字段时,从技术上讲,当前的键盘将消失(你的视图没有任何反应),一个新的键盘将出现(你的keyboardWillShow将再次被调用,你再次将你的视图向上移动170px)。
https://stackoverflow.com/questions/10008497
复制相似问题