I am using a UICollectionView
in combination with a NSFetchedResultsController
. When I fetch new data, I throw them in a SQLite database and my frc gets a notification that it will update. I implement the appropriate delegate methods and insert the new data in a batch update and I don't call reloadData
afterwards. But as soon as the data is inserted, the collectionview scrolls to the top (to make the new items visible?). I would like to interfere this process and imitate the Facebook/9Gag implementation. When there is new data, a button is faded in which lets the user scroll to the top. At the time the button is shown, the new items are already inserted, so the user can also just scroll up himself. I tried the following:
UIScrollViewDelegate
methods to see if I could stop the collectionView from scrolling (none of the methods is called during this update process)willUpdate
and just insert the items when the button is pressed. The problem is that the user cannot scroll up himselfI experimented the same problem, by calling "insertItemAtIndexPaths" to increment data into my collectionView.
I noticed two things : - If you add items AFTER the current visible index path, there's no automatic scroll - If you add items BEFORE the current visible index path, there's no automatic scroll, like you said, but the contentOffset is kept at the same position, but with different contentSize, because you've just added new items.
To deal with this "side effect", I used the solution mentioned here : UICollectionView insert cells above maintaining position (like Messages.app)
As it's explained in the following post, the "CATransaction.setDisableAction(false)" is the key thing to update smoothly the contentOffset position.