ios - iPhone 键盘盖 UITextField

标签 ios iphone keyboard uitextfield

我有一个应用程序,在 Interface Builder 中,我设置了一个 UIView,它在 View 底部附近有一个文本字段。当我运行该应用程序并尝试在该字段中输入文本时,键盘会滑到该字段上方,因此在我再次隐藏键盘之前我看不到我正在输入的内容。

有没有其他人遇到过这个问题并找到了一个既不使父 View 可滚动也不将文本字段移到屏幕更远的位置来解决它的好方法?

最佳答案

通常的解决方案是使用动画将字段(及其上方的所有内容)向上滑动,然后在完成后向下滑动。您可能需要将文本字段和其他一些项目放入另一个 View 并将 View 作为一个单元滑动。 (我称这些东西为“板 block ”,就像“构造板 block ”一样,但那只是我)。但如果您不需要花哨的话,这里是一般的想法。

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

关于ios - iPhone 键盘盖 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1247113/

相关文章:

iphone - 如何在iPhone模拟器中模拟重要的位置更新

ios - 将多个图像拖到 Xcode 7.x 中损坏的 iOS 模拟器? (7.2)

iphone - Apple Mach-O Linker Errors (20) - 架构armv7的 undefined symbol

keyboard - iOS7上的黑键盘

eclipse - 是否可以仅使用键盘在Eclipse中工作?

android - 标签栏随键盘一起上升

ios - 魔法记录,无法保存对象 : contextDidSave == NO, error = nil

ios - "Launch screens may not set custom class names"

iphone - Dropbox 关闭 modalview Controller 不工作

ios - App Delegate 的托管对象上下文为零