title: Swift iOS - Scroll view not scrolling properly
body: <p>I have got a textView and a scrollView. I want to achieve a state where I click in the textView and it will make way for the keyboard. However it seems to work only when I click on the textView for the second time.</p>
  <p>And the code:</p>
  <pre><code>@objc open override func keyboardWillShow(notification: NSNotification) {
      keyboardTapGesture.isEnabled = true
  
      scrollView.isScrollEnabled = true
      let info = notification.userInfo!
  
      let keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
      let contentInsets : UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize?.height ?? 0.0, right: 0.0)
  
      scrollView.contentInset = contentInsets
      scrollView.scrollIndicatorInsets = contentInsets
  
      scrollView.scrollRectToVisible(commentInput.frame, animated: true)
  }
  
  @objc open override func keyboardWillHide(notification: NSNotification) {
      keyboardTapGesture.isEnabled = false
  
      scrollView.contentInset = .zero
      scrollView.scrollIndicatorInsets = .zero
      view.endEditing(true)
      scrollView.isScrollEnabled = false
  }
  </code></pre>
  <p>Thanks for your help.</p>