How do I fix the position of UIView
with image
and label
when the keyboard is moved up?
I made a code to move up my textField
when the keyboard shows, but instead this moves everything.
func textFieldDidEndEditing(_ textField: UITextField) {
moveTextField(textField: rasstoyanietextField, moveDistance: -215, up: false)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
moveTextField(textField: rasstoyanietextField, moveDistance: -215, up: true)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
rasstoyanietextField.resignFirstResponder()
return true
}
func moveTextField(textField: UITextField, moveDistance: Int, up: Bool){
let moveDuration = 0.1
let movement: CGFloat = CGFloat(up ? moveDistance : -moveDistance)
UIView.beginAnimations("animateTextField", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(moveDuration)
self.view.frame = self.view.frame.offsetBy(dx: 0, dy: movement)
UIView.commitAnimations()
}
How could I fix it?