UITextfield 弹跳文本

Lif*_*lus 2 uitextfield ios swift

我为文本字段设置了插图

class PrimaryTextField: UITextField {

    var padding = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)

    override open func textRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, padding)
    }

    override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, padding)
    }

    override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, padding)
    }

}
Run Code Online (Sandbox Code Playgroud)

它运行良好,但当用户在文本字段之间跳转时,文本会弹跳。

在此处输入图片说明

问题只出现在真机上,模拟器没问题。你没有任何想法,如何解决这个问题?

Lif*_*lus 5

keyboardWillHide 和显示通知存在问题。我在那里对约束进行动画处理。我在动画之前添加下面的代码,文本不再弹跳。

    UIView.performWithoutAnimation({
        emailTextField.layoutIfNeeded()
        passwordTextField.layoutIfNeeded()
    })
Run Code Online (Sandbox Code Playgroud)