Friday, 1 February 2019

Dismiss KeyBoard Interactively Bug

Having a problem with my keyboard dismissal. Every time I swipe down on the key board I have this blank Black background that I would like to get rid of. I dont understand why its there. This is hooked up to my tableView.

My keyBoard

What it looks like when I swipe Down

I have the keyBoard on the tableView set as Dismiss Interactively

//                      KeyBoard (move text box above keyboard)




    //KeyBoard - exit when the view is touched
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }



    // Start Editing The Text Field
    func textFieldDidBeginEditing(_ messageTextField: UITextField) {
        moveTextField(messageTextField, moveDistance: -215, up: true)
    }

    // Finish Editing The Text Field
    func textFieldDidEndEditing(_ messageTextField: UITextField) {
        moveTextField(messageTextField, moveDistance: -215, up: false)
    }

    // Hide the keyboard when the return key pressed
    func textFieldShouldReturn(_ messageTextField: UITextField) -> Bool {
        messageTextField.resignFirstResponder()
        return true
    }

    // Move the text field in a pretty animation!
    func moveTextField(_ messageTextField: UITextField, moveDistance: Int, up: Bool) {
        let moveDuration = 0.3
        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()
    }



from Dismiss KeyBoard Interactively Bug

No comments:

Post a Comment