mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-12 06:16:09 +10:00
refactor snapContentOfConversationCollectionViewToBottom(:); logic of textSendAction
This commit is contained in:
@@ -596,34 +596,18 @@ class ConversationViewController: BaseViewController {
|
||||
|
||||
messageToolbar.stateTransitionAction = { [weak self] (messageToolbar, previousState, currentState) in
|
||||
|
||||
if let strongSelf = self {
|
||||
switch currentState {
|
||||
|
||||
switch currentState {
|
||||
case .BeginTextInput:
|
||||
self?.tryFoldFeedView()
|
||||
|
||||
case .BeginTextInput:
|
||||
self?.tryFoldFeedView()
|
||||
self?.snapContentOfConversationCollectionViewToBottom(forceAnimation: true)
|
||||
|
||||
case .TextInputing:
|
||||
let bottom = strongSelf.view.bounds.height - messageToolbar.frame.origin.y
|
||||
println("bottom: \(bottom)")
|
||||
let bottomOffset = bottom - strongSelf.conversationCollectionView.contentInset.bottom
|
||||
case .TextInputing:
|
||||
self?.snapContentOfConversationCollectionViewToBottom()
|
||||
|
||||
if bottomOffset != 0 {
|
||||
|
||||
UIView.animateWithDuration(0.1, delay: 0.0, options: .CurveEaseInOut, animations: {
|
||||
strongSelf.conversationCollectionView.contentInset.bottom = bottom
|
||||
strongSelf.conversationCollectionView.contentOffset.y = strongSelf.conversationCollectionView.contentSize.height - messageToolbar.frame.origin.y
|
||||
}, completion: { _ in })
|
||||
|
||||
//var newContentOffset = strongSelf.conversationCollectionView.contentOffset
|
||||
//newContentOffset.y = strongSelf.conversationCollectionView.contentSize.height - messageToolbar.frame.origin.y
|
||||
//strongSelf.conversationCollectionView.setContentOffset(newContentOffset, animated: true)
|
||||
//println("newContentOffsetY: \(newContentOffset.y)")
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,6 +692,8 @@ class ConversationViewController: BaseViewController {
|
||||
|
||||
self?.cleanTextInput()
|
||||
|
||||
self?.snapContentOfConversationCollectionViewToBottom()
|
||||
|
||||
if text.isEmpty {
|
||||
return
|
||||
}
|
||||
@@ -1288,6 +1274,22 @@ class ConversationViewController: BaseViewController {
|
||||
self.feedView = feedView
|
||||
}
|
||||
|
||||
private func snapContentOfConversationCollectionViewToBottom(forceAnimation forceAnimation: Bool = false) {
|
||||
let bottom = view.bounds.height - messageToolbar.frame.origin.y
|
||||
let bottomOffset = bottom - conversationCollectionView.contentInset.bottom
|
||||
|
||||
guard forceAnimation || bottomOffset != 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
UIView.animateWithDuration(forceAnimation ? 0.25 : 0.1, delay: 0.0, options: .CurveEaseInOut, animations: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.conversationCollectionView.contentInset.bottom = bottom
|
||||
strongSelf.conversationCollectionView.contentOffset.y = strongSelf.conversationCollectionView.contentSize.height - strongSelf.messageToolbar.frame.origin.y
|
||||
}
|
||||
}, completion: { _ in })
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func setConversaitonCollectionViewContentInsetBottom(bottom: CGFloat) {
|
||||
|
||||
Reference in New Issue
Block a user