【发布时间】:2019-03-11 15:02:26
【问题描述】:
我有一个由 NSFetchedResultsController 驱动的 CollectionView。
CollectionViewLayout 是按名称升序排列的水平“轮播”单元格布局。
插入带有海关动画的新物品。
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
if type == NSFetchedResultsChangeType.Insert {
println("Insert Object: \(newIndexPath)")
UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveEaseOut, animations: {
self.collectionView?.insertItems(at: [newIndexPath])
}, completion: { finished in
self.collectionView?.scrollToItem(at: newIndexPath, at: .centeredHorizontally, animated: true)
})
)
...
它可以工作,但动画有点小故障,并且滚动同时发生。
我想滚动到 Item 然后用自定义动画插入它,但如果我在插入之前滚动到 Item 应用程序崩溃。
在这里做什么是正确的?
谢谢
【问题讨论】:
标签: swift animation uicollectionview nsfetchedresultscontroller