【发布时间】:2019-02-09 23:03:55
【问题描述】:
我有一个名为timeline 的collectionView,它以编程方式在倒数第二行滚动:
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
}
}
稍后.. 我正在尝试检测这已完成滚动
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView == timeline {
print("Did finish")
}
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
if scrollView == timeline {
print("Did finish")
}
}
滚动完成后不会触发任何打印语句。我认为部分是因为动画=假。当我将其设置为 true 时,它会打印出是否正确完成 - 我认为特别是 scrollViewDidEndScrollingAnimation 打印,即使 scrollViewDidEndDecelerating 仍然没有执行任何操作,因为它是以编程方式滚动的。
如何检测到此卷轴已完成?
【问题讨论】:
标签: ios swift uiscrollview uicollectionview