我有我的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 -當下) –