title: iOS keyboard hides a UITextField
body: <p>When I press on a <code>UITextField</code> that is on the lower part of the screen, it is hidden by the keyboard.
  What I wanted to do is moving up the view, with the standard iOS animation, reaching the <code>UITextField</code> that in which I am inserting some text.
  I am developing the app in <strong>Swift 5</strong> (Xcode 10.2)</p>
  
  <p>The result that I have reached is that now I can move the view (a little earlier than desired) but the view moves every time I press on a <code>UITextField</code>, not only the one that will be hided by the keyboard.</p>
  
  <pre class="lang-swift prettyprint-override"><code>class ViewController: UIViewController {
      deinit {
          NotificationCenter.default.removeObserver(self)
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
          NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
      }
  
      @objc func keyboardWillShow(notification: NSNotification) {
          guard let userInfo = notification.userInfo else {
              return
          }
  
          guard let keyboardSize = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
              return
          }
  
          let keyboardFrame = keyboardSize.cgRectValue
  
          if self.view.frame.origin.y == 0 {
              self.view.frame.origin.y -= keyboardFrame.height
          }
      }
  
      @objc func keyboardWillHide(notification: NSNotification) {
          guard let userInfo = notification.userInfo else {
              return
          }
  
          guard let keyboardSize = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
              return
          }
  
          let keyboardFrame = keyboardSize.cgRectValue
  
          if self.view.frame.origin.y != 0 {
              self.view.frame.origin.y += keyboardFrame.height
          }
      }
  }
  
  </code></pre>
  
  <p>The result that I want to obtain is that if the user presses on a <code>UITextField</code> that will be hided by the keyboard, then, a little bit after the keyboard appeared, the view is moved up until the user can see the <code>UITextField</code> that has pressed.</p>
  
  <p>I've searched a long for a solution to this problem but all others that I've seen seems outdated or not doing what I'm trying to achieve.</p>