From dfea704e7e02359253236c06bb8c66205d4fea10 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 27 Oct 2015 14:09:25 +0800 Subject: [PATCH 1/2] fix adjust contentInset in Conversation with feed --- .../ConversationViewController.swift | 38 ++++++++++++++----- Yep/Views/Feed/FeedView.swift | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index fcbf96ba..928eb907 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -747,6 +747,7 @@ class ConversationViewController: BaseViewController { dispatch_async(dispatch_get_main_queue()) { self?.updateConversationCollectionViewWithMessageIDs(nil, messageAge: .New, scrollToBottom: true, success: { _ in + println("B conversationCollectionView.contentInset: \(self?.conversationCollectionView.contentInset)") }) } @@ -1299,6 +1300,8 @@ class ConversationViewController: BaseViewController { conversationCollectionView.contentInset.top = 64 + feedViewHeight + conversationCollectionViewContentInsetYOffset setConversaitonCollectionViewContentInsetBottom(CGRectGetHeight(messageToolbar.bounds) + sectionInsetBottom) + + println("A conversationCollectionView.contentInset: \(conversationCollectionView.contentInset)") } private var messageHeights = [String: CGFloat]() @@ -1906,26 +1909,33 @@ class ConversationViewController: BaseViewController { let keyboardAndToolBarHeight = adjustHeight - let blockedHeight = topBarsHeight + keyboardAndToolBarHeight + let blockedHeight = topBarsHeight + (feedView != nil ? FeedView.foldHeight : 0) + keyboardAndToolBarHeight let visibleHeight = conversationCollectionView.frame.height - blockedHeight // cal the height can be used let useableHeight = visibleHeight - conversationCollectionView.contentSize.height - let totalHeight = conversationCollectionView.contentSize.height + blockedHeight + newMessagesTotalHeight + //let totalHeight = conversationCollectionView.contentSize.height + blockedHeight + newMessagesTotalHeight - if totalHeight > conversationCollectionView.frame.height { + //if totalHeight > conversationCollectionView.frame.height { + + //let newContentHeight = conversationCollectionView.contentSize.height + newMessagesTotalHeight + + println("newMessagesTotalHeight: \(newMessagesTotalHeight)") + println("useableHeight: \(useableHeight)") + + if newMessagesTotalHeight > useableHeight { UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { [weak self] in if let strongSelf = self { - if (useableHeight > 0) { - let contentToScroll = newMessagesTotalHeight - useableHeight - strongSelf.conversationCollectionView.contentOffset.y += contentToScroll - - } else { +// if (useableHeight > 0) { +// let contentToScroll = newMessagesTotalHeight - useableHeight +// strongSelf.conversationCollectionView.contentOffset.y += contentToScroll +// +// } else { if scrollToBottom { let newContentSize = strongSelf.conversationCollectionView.collectionViewLayout.collectionViewContentSize() let newContentOffsetY = newContentSize.height - strongSelf.conversationCollectionView.frame.height + keyboardAndToolBarHeight @@ -1934,14 +1944,24 @@ class ConversationViewController: BaseViewController { } else { strongSelf.conversationCollectionView.contentOffset.y += newMessagesTotalHeight } - } +// } } }, completion: { _ in success(true) + + println("strongSelf.conversationCollectionView.contentOffset: \(self.conversationCollectionView.contentOffset)") }) } else { +// UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { [weak self] in +// let contentToScroll = newMessagesTotalHeight - useableHeight +// self?.conversationCollectionView.contentOffset.y += contentToScroll +// +// }, completion: { _ in +// success(true) +// }) + success(true) } diff --git a/Yep/Views/Feed/FeedView.swift b/Yep/Views/Feed/FeedView.swift index 6fdfb164..0df9cbee 100644 --- a/Yep/Views/Feed/FeedView.swift +++ b/Yep/Views/Feed/FeedView.swift @@ -162,7 +162,7 @@ class FeedView: UIView { var normalHeight: CGFloat { guard let feed = feed else { - return 60 + return FeedView.foldHeight } let rect = feed.body.boundingRectWithSize(CGSize(width: FeedView.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedView.textAttributes, context: nil) From 402e05447396be3b84444768ba83eafe512432fa Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 27 Oct 2015 14:16:46 +0800 Subject: [PATCH 2/2] clean code --- .../ConversationViewController.swift | 44 ++++--------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 928eb907..6e4a5240 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -718,7 +718,7 @@ class ConversationViewController: BaseViewController { sendText(text, toRecipient: withFriend.userID, recipientType: "User", afterCreatedMessage: { [weak self] message in dispatch_async(dispatch_get_main_queue()) { - self?.updateConversationCollectionViewWithMessageIDs(nil, messageAge: .New, scrollToBottom: true, success: { success in + self?.updateConversationCollectionViewWithMessageIDs(nil, messageAge: .New, scrollToBottom: true, success: { _ in }) } @@ -747,7 +747,6 @@ class ConversationViewController: BaseViewController { dispatch_async(dispatch_get_main_queue()) { self?.updateConversationCollectionViewWithMessageIDs(nil, messageAge: .New, scrollToBottom: true, success: { _ in - println("B conversationCollectionView.contentInset: \(self?.conversationCollectionView.contentInset)") }) } @@ -1300,8 +1299,6 @@ class ConversationViewController: BaseViewController { conversationCollectionView.contentInset.top = 64 + feedViewHeight + conversationCollectionViewContentInsetYOffset setConversaitonCollectionViewContentInsetBottom(CGRectGetHeight(messageToolbar.bounds) + sectionInsetBottom) - - println("A conversationCollectionView.contentInset: \(conversationCollectionView.contentInset)") } private var messageHeights = [String: CGFloat]() @@ -1916,52 +1913,27 @@ class ConversationViewController: BaseViewController { // cal the height can be used let useableHeight = visibleHeight - conversationCollectionView.contentSize.height - //let totalHeight = conversationCollectionView.contentSize.height + blockedHeight + newMessagesTotalHeight - - //if totalHeight > conversationCollectionView.frame.height { - - //let newContentHeight = conversationCollectionView.contentSize.height + newMessagesTotalHeight - - println("newMessagesTotalHeight: \(newMessagesTotalHeight)") - println("useableHeight: \(useableHeight)") - if newMessagesTotalHeight > useableHeight { UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { [weak self] in if let strongSelf = self { -// if (useableHeight > 0) { -// let contentToScroll = newMessagesTotalHeight - useableHeight -// strongSelf.conversationCollectionView.contentOffset.y += contentToScroll -// -// } else { - if scrollToBottom { - let newContentSize = strongSelf.conversationCollectionView.collectionViewLayout.collectionViewContentSize() - let newContentOffsetY = newContentSize.height - strongSelf.conversationCollectionView.frame.height + keyboardAndToolBarHeight - strongSelf.conversationCollectionView.contentOffset.y = newContentOffsetY + if scrollToBottom { + let newContentSize = strongSelf.conversationCollectionView.collectionViewLayout.collectionViewContentSize() + let newContentOffsetY = newContentSize.height - strongSelf.conversationCollectionView.frame.height + keyboardAndToolBarHeight + strongSelf.conversationCollectionView.contentOffset.y = newContentOffsetY - } else { - strongSelf.conversationCollectionView.contentOffset.y += newMessagesTotalHeight - } -// } + } else { + strongSelf.conversationCollectionView.contentOffset.y += newMessagesTotalHeight + } } }, completion: { _ in success(true) - - println("strongSelf.conversationCollectionView.contentOffset: \(self.conversationCollectionView.contentOffset)") }) } else { -// UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { [weak self] in -// let contentToScroll = newMessagesTotalHeight - useableHeight -// self?.conversationCollectionView.contentOffset.y += contentToScroll -// -// }, completion: { _ in -// success(true) -// }) - success(true) }