title: Swift Keyboard animation moving up and down
body: <p>When a text field is clicked, my app moves down into a white space and then back up with the keyboard. How do I get it to stop doing that? I just want to get the screen to move up a little when the keyboard is activated. 
  This question is different than the other Swift keyboard questions because it uses the code from the book <em>I0S8 for programmers</em> from Deitel. And solving this problem might help others who own the book. 
  Thanks, </p>
  
  <pre><code>override func viewWillAppear(animated: Bool) {
      super.viewWillAppear(animated)
      NSNotificationCenter.defaultCenter().addObserver(self,
          selector: "keyboardWillShow:",
          name: UIKeyboardWillShowNotification,
          object: nil)
      NSNotificationCenter.defaultCenter().addObserver(self,
          selector: "keyboardWillHide:",
          name: UIKeyboardWillHideNotification,
          object: nil)        // listen for keyboard show/hide notifications
  }
  override func viewWillDisappear(animated: Bool) {
      super.viewWillDisappear(animated)
      NSNotificationCenter.defaultCenter().removeObserver(self,
          name: UIKeyboardWillShowNotification, object: nil)
      NSNotificationCenter.defaultCenter().removeObserver(self,
          name: UIKeyboardWillHideNotification, object: nil)        // unregister for keyboard show/hide notifications
  }
       // called when app receives UIKeyboardWillShowNotification
  func keyboardWillShow(notification: NSNotification) {
      let userInfo = notification.userInfo!
      let frame = userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue!
      let size = frame.CGRectValue().size // keyboard's size
  
      // get duration of keyboard's slide-in animation
      let animationTime = userInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue
  
      // scroll self.tableView so selected UITextField above keyboard
      UIView.animateWithDuration(animationTime) {
          var insets = self.tableView.contentInset
          insets.bottom = size.height
          self.tableView.contentInset = insets
          self.tableView.scrollIndicatorInsets = insets
      }
  }    // called when app receives UIKeyboardWillHideNotification
  func keyboardWillHide(notification: NSNotification) {
      var insets = self.tableView.contentInset
      insets.bottom = 2
      self.tableView.contentInset = insets
      self.tableView.scrollIndicatorInsets = insets
  }
  // hide keyboard if user touches Return key
  func textFieldShouldReturn(textField: UITextField) -&gt; Bool {
      textField.resignFirstResponder()
      return true
  }
  </code></pre>