我有我的UIView里面有两个UIViews。这是我的看法: iOS在键盘之前提起UIView?
在专注于文本字段上,显示键盘和键盘隐藏我的文本字段。我想在键盘之前移动整个TextField View。我发现的代码示例在这里计算器: iPhone Keyboard Covers UITextField
这是代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
我想实现这个,但我有它的麻烦。有人可以解释如何正确地做到这一点?
有一堆关于SOF上的这个问题的问题,请问之前谷歌它,这里是第一个结果http://stackoverflow.com/questions/6435670/keyboard-hides-uitextfield-how-to-solve-这 –
可能重复[如何使UITextField在键盘存在时向上移动](http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is -当下) –