0

Textfield animation view moves upward 240 then the keyboard and view between there is a black background. I need to fix it.

The program I tried:

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

func textFieldDidEndEditing(_ textField: UITextField) {
    animateViewMoving(up: false, moveValue: 240)
}

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()
    self.view.backgroundColor = UIColor.red
}

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

func textFieldDidEndEditing(_ textField: UITextField) {
    animateViewMoving(up: false, moveValue: 240)
}

I expect the black background colour to be replaced with the white background but it's not working. I tried with view background colour the actual colour I need white colour.

my screen

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Make Outlet of view which you want to move up and set outlet instead of UIVIEW. and try – Dhaval Umraliya Apr 18 '19 at 04:12
  • Instead of hard coded 240, get the height of the keyboard and move view to that value. [This](https://stackoverflow.com/questions/31774006/how-to-get-height-of-keyboard) might help!. – Kamran Apr 18 '19 at 04:21

1 Answers1

0

I think this is the window color. You can try changing the color by UIApplication.shared.keyWindow?.backgroundColor = UIColor.white

ayon.gupta
  • 178
  • 7
  • @kranthibabu please upvote if the answer was correct – ayon.gupta Apr 18 '19 at 05:32
  • This is hack at its best :D. Will fail if the UIView background color is anything but white. Better option still would be to use keyboard height and move accordingly as mentioned by @Kamran in the comments section of the question – iOSer Apr 18 '19 at 05:34
  • I was upvoted but its show "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score." – kranthi babu Apr 18 '19 at 05:34