title: Maintain visibility of focused UITextView in a UITableView when showing Keyboard
body: <p>I am building a form dynamically that has various types of UI elements for each <code>UITableViewCell</code>. </p>
  
  <p>There is one <code>UITableViewCell</code> that contains a <code>UITextView</code> and I want to be able to maintain visibility when showing the keyboard. I have looked at the other similar questions, but have been unable to find a solution.</p>
  
  <p>I wrote the Swift version of what is recommended by: <a href="https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html" rel="nofollow">Apple's Managing Keyboard</a></p>
  
  <p>It does not work for two reasons. 
  1.) The Keyboard notification is fired before the <code>TextViewWillBeginEditing</code>.
  2.) The frame of the <code>UITextView</code> is in relation to the superview which is the <code>UITableViewCell</code>, so the check is wrong.</p>
  
  <p>Here is my current code: </p>
  
  <pre><code>func adjustTableViewForKeyboard(notification: NSNotification) {
          let userInfo = notification.userInfo!
  
          let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
          let keyboardViewEndFrame = view.convertRect(keyboardScreenEndFrame, fromView: view.window)
  
          if notification.name == UIKeyboardWillHideNotification {
              self.tableView.contentInset = UIEdgeInsetsZero
          } else {
              self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardViewEndFrame.height, right: 0)
  
              rect = self.view.frame;
              rect!.size.height -= keyboardViewEndFrame.height
  
          }
          self.tableView.scrollIndicatorInsets = self.tableView.contentInset
  
      }
  
  
  func textViewDidBeginEditing(textView: UITextView) {
          self.activeTextView = textView;
  
          if(activeTextView != nil){
              // This check does NOT work due to the TextView's superview is the cell.
              if(!CGRectContainsPoint(rect!, (activeTextView?.frame.origin)!)){
                  self.tableView.scrollRectToVisible((activeTextView?.frame)!, animated: true)
              }
  
          }
      }
  </code></pre>
  
  <p>This works in terms of being able to scroll to all cells, but I also want to make sure the <code>UITextView</code> is not hidden by keyboard. </p>