title: Swift Table View (Chat UI) if keyboard was shown, whole view getting lower
body: <p>i try to create a Chat UI. Therefore i added a Tableview  and a textfield below. If a user wants to type in the textfield, the whole view should go up and thats work fine. If the user ends typing and the keyboard should be hidden, the first time the view moves a bit lower and the seccond time it moves lower as well. It looks like the following screenshots:</p>
  
  <p>is used the following code:</p>
  
  <pre><code>   override func viewDidLoad() {
  
      super.viewDidLoad()
      self.myChat.separatorStyle = .none
      getChatId()
      myChat.allowsSelection = false;
  
  
      newMessage.delegate = self
      // Do any additional setup after loading the view.
  
      NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
      NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
  }
  
  @objc func keyboardWillShow(notification: NSNotification) {
      if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
          if self.view.frame.origin.y == 0{
              self.view.frame.origin.y -= keyboardSize.height
          }
      }
  }
  
  @objc func keyboardWillHide(notification: NSNotification) {
      if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
          if self.view.frame.origin.y != 0{
              self.view.frame.origin.y += keyboardSize.height-1
          }
      }
  }[![normally it should look like this][1]][1]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dXbqF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dXbqF.jpg" alt="the third time i try to tipe in the textfield is completely invisible and at the top is a black bar"></a></p>
  
  <p>regards</p>