I am making a sign up screen and would like to update a few top anchors so that when the keyboard appears, the top anchor constant decreases and the keyboard doesn't cover any text fields.
I have created a topConstant variable:
var constraintConstant: CGFloat = 35
And have set up my views as follows:
view.addSubview(passwordTextField)
passwordTextField.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 25).isActive = true
passwordTextField.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -25).isActive = true
passwordTextField.heightAnchor.constraint(equalToConstant: 50).isActive = true
passwordTextField.topAnchor.constraint(equalTo: emailTextField.bottomAnchor, constant: constraintConstant).isActive = true
Then I have written this code:
func textFieldDidBeginEditing(_ textField: UITextField) {
constraintConstant = 15
view.layoutIfNeeded()
}
I'n not sure why the constriants aren't updating. Any ideas?