I have a collectionView called timeline that is scrolling programmatically on the second to last line here:
internal func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if !onceOnly {
let indexToScrollTo = IndexPath(row: self.posts.count - 1, section: 0)
collectionView.scrollToItem(at: indexToScrollTo, at: .left, animated: false)
let firstPost = posts.first?.timeStamp
let firstOfFirstMonth = firstPost?.startOfMonth()
let diff = posts.last?.timeStamp.months(from: firstOfFirstMonth!)
//self.currentPostMonth = diff
let monthCellIndexPath = IndexPath(row: diff!, section: 0)
timeline.scrollToItem(at: monthCellIndexPath, at: .centeredHorizontally, animated: false)
onceOnly = true
}
}
later.. I am attempting to detect that this has finished scrolling with
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView == timeline {
print("Did finish")
}
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
if scrollView == timeline {
print("Did finish")
}
}
Neither print statement fires once the scroll has completed. I think partially because animation = false. When I set that to true, it prints Did finish correctly - I think specifically scrollViewDidEndScrollingAnimation prints even though scrollViewDidEndDecelerating still does nothing because its being scrolled programatically.
How can I detect that this scroll has finished?