我面臨與應用集合視圖快照后滾動到 IndexPath 相關的問題。為此,我撰寫了以下代碼
dataSource.apply(snapshot, animatingDifferences: false, completion: {
self.scrollToIndex(self.visibleIndex)
})
不幸的是,它在 < iOS 15 中對我不起作用
注意:適用于 iOS 15 及更高版本
uj5u.com熱心網友回復:
嘗試在短暫延遲后執行滾動操作:
dataSource.apply(snapshot, animatingDifferences: false, completion: {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() .milliseconds(10)) {[weak self] in
if let self = self, let indexToScrollTo = self.visibleIndex {
self.scrollToIndex(indexToScrollTo)
}
}
})
uj5u.com熱心網友回復:
你可以使用這個
self.collectionView.scrollToItem(at:IndexPath(item: index, section: 0), at: .right, animated: false)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/394797.html
標籤:ios 迅速 代码 用户界面 uicollectionviewdiffabledatasource
上一篇:接受T&C后中斷購買不呼叫代表
下一篇:將狀態資料傳遞給ipc函式呼叫
