Ios 如何在UICollectionView中保持垂直滚动位置
我已经尝试了堆栈溢出的所有答案,但没有一个对我有用 我有一个加载更多消息按钮,可以加载以前的消息。我希望能够保持垂直位置Ios 如何在UICollectionView中保持垂直滚动位置,ios,swift,core-data,uicollectionview,nsfetchedresultscontroller,Ios,Swift,Core Data,Uicollectionview,Nsfetchedresultscontroller,我已经尝试了堆栈溢出的所有答案,但没有一个对我有用 我有一个加载更多消息按钮,可以加载以前的消息。我希望能够保持垂直位置 var blockOperations = [NSBlockOperation]() func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType t
var blockOperations = [NSBlockOperation]()
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
if type == .Insert {
blockOperations.append(NSBlockOperation(block: {
self.collectionView?.insertItemsAtIndexPaths([newIndexPath!])
}))
}
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
collectionView?.performBatchUpdates({
for operation in self.blockOperations {
operation.start()
}
}, completion: { (completed) in
let lastItem = self.fetchedResultsControler.sections![0].numberOfObjects - 1
let indexPath = NSIndexPath(forItem: lastItem, inSection: 0)
//self.collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)
})
}
有没有一个有效的方法来做到这一点