     var lastTimeMessagesCount: UInt = 0
 
     var conversationCollectionViewHasBeenMovedToBottomOnce = false
+
+
+    // Keyboard 动画相关
+    var conversationCollectionViewContentOffsetBeforeKeyboardWillShow = CGPointZero
+    var conversationCollectionViewContentOffsetBeforeKeyboardWillHide = CGPointZero
+    //var messageToolbarBottomConstraintConstantAfterKeyboardWillShow: CGFloat = 0
+    var isKeyboardVisible = false
+    var keyboardHeight: CGFloat = 0
+    //var firstTime = true
+
+    var keyboardShowTimes = 0 {
+        willSet {
+            println("set keyboardShowTimes \(newValue)")
+
+            if newValue == 0 {
+                if !self.isKeyboardVisible {
+                    var contentOffset = self.conversationCollectionViewContentOffsetBeforeKeyboardWillShow
+                    contentOffset.y += keyboardHeight
+                    self.conversationCollectionView.setContentOffset(contentOffset, animated: true)
+
+                    println("fire setContentOffset")
+
+                    self.isKeyboardVisible = true
+
+                } else {
+//                    var contentOffset = conversationCollectionView.contentOffset//self.conversationCollectionViewContentOffsetBeforeKeyboardWillShow
+//
+//                    let dy = /*keyboardHeight*/self.messageToolbarBottomConstraint.constant - (messageToolbarBottomConstraintConstantAfterKeyboardWillShow /*+ self.messageToolbar.intrinsicContentSize().height*/)//self.messageToolbarBottomConstraint.constant
+//                    contentOffset.y += dy
+//                    println("XXXcontentOffset.y += \(self.messageToolbarBottomConstraint.constant) - \(messageToolbarBottomConstraintConstantAfterKeyboardWillShow)")
+//                    self.conversationCollectionView.setContentOffset(contentOffset, animated: true)
+//
+//                    firstTime = true
+                }
+            }
+        }
+    }
+
 
     @IBOutlet weak var conversationCollectionView: UICollectionView!
 

                self.messageToolbarBottomConstraint.constant = 0
                self.view.layoutIfNeeded()

                self.conversationCollectionView.contentOffset.y -= keyboardHeight
                self.conversationCollectionView.contentInset.bottom -= keyboardHeight

            }, completion: { (finished) -> Void in
            })
        }
    }
}

// MARK: UICollectionViewDataSource, UICollectionViewDelegate

            let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
            let keyboardHeight = keyboardEndFrame.height


            println("animationDuration: \(animationDuration)")
            println("keyboardHeight: \(keyboardHeight)")


            let lastTimeKeyboardHeight = self.keyboardHeight

            self.keyboardHeight = keyboardHeight

//            if isKeyboardVisible && firstTime {
//                messageToolbarBottomConstraintConstantAfterKeyboardWillShow = self.messageToolbarBottomConstraint.constant
//                firstTime = false
//            }
            UIView.animateWithDuration(animationDuration, delay: 0, options: UIViewAnimationOptions(animationCurveValue << 16), animations: { () -> Void in
                self.messageToolbarBottomConstraint.constant = keyboardHeight
                self.view.layoutIfNeeded()

                self.conversationCollectionView.contentInset.bottom = self.messageToolbar.intrinsicContentSize().height + keyboardHeight

            }, completion: { (finished) -> Void in
                println("self.keyboardHeight: \(self.keyboardHeight)")

                self.keyboardShowTimes -= 1
            })
        }
    }

    func handleKeyboardWillHideNotification(notification: NSNotification) {
        println("hideKeyboard")

        conversationCollectionViewContentOffsetBeforeKeyboardWillHide = conversationCollectionView.contentOffset

        if let userInfo = notification.userInfo {
            let animationDuration: NSTimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
