0

I submitted the following code from here so that when the keyboard appears, the view will move up.

 func textFieldDidBeginEditing(_ textField: UITextField) {
    animateViewMoving(up: true, moveValue: 100)
}

func textFieldDidEndEditing(_ textField: UITextField) {
    animateViewMoving(up: false, moveValue: 100)
}
func animateViewMoving (up:Bool, moveValue :CGFloat){
    let movementDuration:TimeInterval = 0.3
    let movement:CGFloat = ( up ? -moveValue : moveValue)
    UIView.beginAnimations( "animateView", context: nil)
    UIView.setAnimationBeginsFromCurrentState(true)
    UIView.setAnimationDuration(movementDuration )
    self.view.frame = self.view.frame.offsetBy(dx: 0, dy: movement)
    UIView.commitAnimations()
}

But when I tried implementing the code, the view does not move: Here is the first view:

enter image description here

And after I press the textView:

enter image description here

You can see that the keyboard blocks the textView. What would you recommend so that this code executes appropriately?

EverythingEnds
  • 77
  • 1
  • 11
  • 1
    One solution to making the view move up to not block any content could be found here: https://stackoverflow.com/a/50327117/10200990 It works by using a framework and using two lines of code in your AppDelegate – sfung3 Aug 04 '19 at 08:30
  • It works, but it would be nice if the view would move up slightly higher because the Reply button at the bottom is still blocked. Do you know how to adjust this? – EverythingEnds Aug 04 '19 at 08:49

0 Answers0