title: Issue moving view when keyboard appears Swift
body: <p>I am using a scroll view and auto layout to move the view when the keyboard appears and hides one of my text input elements. To do so I am using the below functions. </p>
  
  <p>The issue is that I can't get it to work for both the text field and text view. I have researched a lot and tried implementing all answers I have found on SO and other resources but most answers only deal with single text fields not multiple and I have not found a single solution for a text field and a text view.</p>
  
  <p>I know that the below code is designed for text fields but I am trying to modify it to work with text views as well because out of all the different ways I haver seen to move the view when the keyboard appears this works the best for me.</p>
  
  <p>I am wondering if there is a way to get the view to move for both my text field and text view using my current code. Also Im wondering if this is the best way to be moving the view.</p>
  
  <p>Functions to move the view when keyboard appears:</p>
  
  <pre><code>func keyboardWillShow(sender: NSNotification) {
      let info: NSDictionary = sender.userInfo!
      let value: NSValue = info.valueForKey(UIKeyboardFrameBeginUserInfoKey) as! NSValue
      let keyboardSize: CGSize = value.CGRectValue().size
      let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height + 20, 0.0)
      scrollView.contentInset = contentInsets
  
      var aRect: CGRect = self.view.frame
      aRect.size.height -= keyboardSize.height
      let activeTextFieldRect: CGRect? = myTextField?.frame
      let activeTextFieldOrigin: CGPoint? = activeTextFieldRect?.origin
      if (!CGRectContainsPoint(aRect, activeTextFieldOrigin!)) {
          scrollView.scrollRectToVisible(activeTextFieldRect!, animated:true)
      }
  }
  
  func keyboardWillHide(sender: NSNotification) {
      let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
      scrollView.contentInset = contentInsets
  }
  
  func textFieldDidBeginEditing(textField: UITextField) {
      myTextField = textField
      scrollView.scrollEnabled = true
  }
  
  func textFieldDidEndEditing(textField: UITextField) {
      myTextField = nil
      scrollView.scrollEnabled = true
  } 
  </code></pre>
  
  <p>I have tried implementing <code>textViewDidBeginEditing</code> and <code>textViewDidEndEditing</code> and then assigning that in place of <code>myTextView</code> in this line: <code>let activeTextFieldRect: CGRect? = myTextField?.frame</code> but that seems like a sloppy way to do this and doesn't work anyway. Any help is much appreciated.</p>