0

这是键盘隐藏文本字段的一个非常常见的问题。在 SO 上也为此发布了很多解决方案。

所以目前我指的是以下帖子,该帖子在 iPad 纵向模式下运行良好,但在 iPad 横向模式下,视图向左滑动,因为我希望视图向上移动。

- (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];
}
4

1 回答 1

0

由于 iPad 本身为键盘提供了很好的选项,如“Undock”和“Split”,一般我们不需要排列 Text Field。虽然考虑到您是否需要使用[[UIDevice currentDevice] orientation]基于该动画文本字段框架检查设备当前方向的问题。

于 2012-06-13T13:46:40.727 回答