By default Collection View maintains content offset while inserting cells. On the other hand I'd like to insert cells above the currently displaying ones so that they appear above the screen top edge like Messages.app do when you load earlier messages. Does anyone know the way to achieve it?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Not the most elegant but quite simple and working solution I stuck with for now. Works only with linear layout (not grid) but it's fine for me.
This seems to be working so far. Reload the collection, scroll the previously first message to the top without animation.
This is what I learned from JSQMessagesViewController: How maintain scroll position?. Very simple, useful and NO flicker!
A few of the suggested approaches had varying degrees of success for me. I eventually used a variation of the subclassing and
prepareLayout
option Peter Stajger putting my offset correction infinalizeCollectionViewUpdates
. However today as I was looking at some additional documentation I foundtargetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint)
and I think that feels a lot more like the intended location for this type of correction. So this is my implementation using that. Note my implmentation was for a horizontal collection butcellsInsertingToTheLeft
could be easily updated ascellsInsertingAbove
and the offset corrected accordingly.I managed to write a solution which works for cases when inserting cells at the top and bottom at the same time.
I have used the @James Martin approach, but if you use
coredata
andNSFetchedResultsController
the right approach is store the number of earlier messages loaded in_earlierMessagesLoaded
and check the value in thecontrollerDidChangeContent: