A solution to the problem of blocking the input box when the swift3.0 keyboard pops up

  • 2020-05-15 02:14:52
  • OfStack

The following code is the site to introduce the swift3.0 keyboard pop-up shielding input box problem solution code analysis, the specific code is as follows;


extension LoginViewController:UITextFieldDelegate
{
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
// Keyboard retract, view Put down the 
UIView.animate(withDuration: 0.4, animations: {
self.view.frame.origin.y = 0
})
return true
}
func textFieldDidBeginEditing(_ textView:UITextField) {
//view Bounce to follow the keyboard, high can be defined according to their own 
UIView.animate(withDuration: 0.4, animations: {
self.view.frame.origin.y = -150
})
}
}

Ok, this is the end of the code, I hope to help you!


Related articles: