title: Keyboard hides UITextView when it appears
body: <p>I have set my <code>UIkeyboarddismissmode</code> to be <code>.Interactive</code>, and I do not know how to resize the <code>UITextView</code> so that the keyboard would not cover the content. I also have a <code>UIToolbar</code> as the <code>inputaccessory</code>. </p>
  
  <p>Here is my code.</p>
  
  <pre><code>@IBOutlet weak var textView: UITextView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      self.addDoneButtonOnKeyboard()
  
      self.textView.keyboardDismissMode = .Interactive
  }
  
  override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(true)
  
      // Add notification about keyboard
      NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardNotification:"), name:UIKeyboardWillShowNotification, object: nil)
      NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardNotification:"), name:UIKeyboardWillHideNotification, object: nil)
      //        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardFrameDidChange:"), name:UIKeyboardWillChangeFrameNotification, object: nil)
  }
  
  override func viewDidDisappear(animated: Bool) {
      super.viewDidDisappear(true)
      NSNotificationCenter.defaultCenter().removeObserver(UIKeyboardWillShowNotification)
      NSNotificationCenter.defaultCenter().removeObserver(UIKeyboardWillHideNotification)
  }
  
  
  // The UIToolbar
  
  var toolbar = UIToolbar()
  
  func addDoneButtonOnKeyboard()
  {
      var doneToolbar: UIToolbar = UIToolbar(frame: CGRectMake(0, 0, 320, 44))
      doneToolbar.barStyle = UIBarStyle.Default
  
      var flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
      var photo: UIBarButtonItem = UIBarButtonItem(title: "Add Photo", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("photoButtonAction"))
      var done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: Selector("doneButtonAction"))
  
      var items = NSMutableArray()
      items.addObject(photo)
      items.addObject(flexSpace)
      items.addObject(done)
  
      doneToolbar.items = items
      doneToolbar.sizeToFit()
  
      doneToolbar.tintColor = UIColor(red: 240/225, green: 42/225, blue: 20/225, alpha: 1)
      doneToolbar.translucent = true
  
      self.toolbar = doneToolbar
      self.textView.inputAccessoryView = self.toolbar
  }
  
  func keyboardFrameDidChange(notification: NSNotification) {
      if let userInfo = notification.userInfo {
          var endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue()
          var beginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()
  
          let animationCurveRawNSN = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber
          let animationCurveRaw = animationCurveRawNSN?.unsignedLongValue ?? UIViewAnimationOptions.CurveEaseInOut.rawValue
          let animationCurve:UIViewAnimationOptions = UIViewAnimationOptions(rawValue: animationCurveRaw)
  
          var animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
  
          var newFrame = self.textView.frame
          var keyboardFrameEnd = self.view.convertRect(endFrame!, toView: nil)
          var keyboardFrameBegin = self.view.convertRect(beginFrame!, toView: nil)
  
          newFrame.origin.y -= (keyboardFrameBegin.origin.y - keyboardFrameEnd.origin.y)
          self.textView.frame = newFrame
  
          UIView.animateWithDuration(animationDuration,
              delay: NSTimeInterval(0),
              options: animationCurve,
              animations: { self.view.layoutIfNeeded() },
              completion: nil)
      }
  
  }
  </code></pre>
  
  <p>The above code only makes the <code>textView</code> move in a weird way and I don't know how to achieve the effect like the Message app. </p>
  
  <p>Update:</p>
  
  <pre><code>func keyboardFrameEnd(notification: NSNotification) {
      if let userInfo = notification.userInfo {
          var endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue()
  
          // Change contentInset
          self.textView.contentInset.bottom = endFrame!.height
          self.textView.scrollIndicatorInsets.bottom = endFrame!.height
      }
  }
  </code></pre>
  
  <p>I changed my code to above. But sometimes when I release the keyboard halfway, the scrollView would suddenly bounce to the bottom which is very weird. Any suggestion?</p>