Photos(PHFetchResultChangeDetails)
来源:互联网 发布:mac唇膏试色最全 编辑:程序博客网 时间:2024/04/27 14:58
Photos(PHChange)
Photos(PHObjectChangeDetails)
Photos(PHFetchResultChangeDetails)
PHFetchResultChangeDetails主要用于记录PHFetchResult的变动,这样可以同时判断多个数据是否有变动。
1 获取PHFetchResult
/// 变化前public var fetchResultBeforeChanges: PHFetchResult { get }/// 变化后public var fetchResultAfterChanges: PHFetchResult { get }
2 获取变动信息
/// 是否有变动public var hasIncrementalChanges: Bool { get }/// 删除对象的位置public var removedIndexes: NSIndexSet? { get }/// 删除的对象public var removedObjects: [PHObject] { get }/// 插入对象的位置public var insertedIndexes: NSIndexSet? { get }/// 插入的对象public var insertedObjects: [PHObject] { get }/// 有变化的对象位置public var changedIndexes: NSIndexSet? { get }/// 有变化的对象public var changedObjects: [PHObject] { get }/// 移动照片public func enumerateMovesWithBlock(handler: (Int, Int) -> Void)/// 是否有移动public var hasMoves: Bool { get }
3 比较PHFetchResult
/// 获取两个PHFetchResult的差异////// - parameter fromResult : PHFetchResult/// - parameter toResult : PHFetchResult/// - parameter changedObjects : [PHObject]////// - returns: PHFetchResultChangeDetailspublic convenience init(fromFetchResult fromResult: PHFetchResult, toFetchResult toResult: PHFetchResult, changedObjects: [PHObject])
4 实战演练
func photoLibraryDidChange(changeInfo: PHChange!) { // Photos may call this method on a background queue; // switch to the main queue to update the UI. dispatch_async(dispatch_get_main_queue()) { // Check for changes to the displayed album itself // (its existence and metadata, not its member assets). if let albumChanges = changeInfo.changeDetailsForObject(self.displayedAlbum) { // Fetch the new album and update the UI accordingly. self.displayedAlbum = albumChanges.objectAfterChanges as PHAssetCollection self.navigationController.navigationItem.title = self.displayedAlbum.localizedTitle } // Check for changes to the list of assets (insertions, deletions, moves, or updates). if let collectionChanges = changeInfo.changeDetailsForFetchResult(self.assetsFetchResults) { // Get the new fetch result for future change tracking. self.assetsFetchResults = collectionChanges.fetchResultAfterChanges if collectionChanges.hasIncrementalChanges { // Get the changes as lists of index paths for updating the UI. var removedPaths: [NSIndexPath]? var insertedPaths: [NSIndexPath]? var changedPaths: [NSIndexPath]? if let removed = collectionChanges.removedIndexes { removedPaths = self.indexPathsFromIndexSet(removed) } if let inserted = collectionChanges.insertedIndexes { insertedPaths = self.indexPathsFromIndexSet(inserted) } if let changed = collectionChanges.changedIndexes { changedPaths = self.indexPathsFromIndexSet(changed) } // Tell the collection view to animate insertions/deletions/moves // and to refresh any cells that have changed content. self.collectionView.performBatchUpdates( { if removedPaths { self.collectionView.deleteItemsAtIndexPaths(removedPaths) } if insertedPaths { self.collectionView.insertItemsAtIndexPaths(insertedPaths) } if changedPaths { self.collectionView.reloadItemsAtIndexPaths(changedPaths) } if (collectionChanges.hasMoves) { collectionChanges.enumerateMovesWithBlock() { fromIndex, toIndex in let fromIndexPath = NSIndexPath(forItem: fromIndex, inSection: 0) let toIndexPath = NSIndexPath(forItem: toIndex, inSection: 0) self.collectionView.moveItemAtIndexPath(fromIndexPath, toIndexPath: toIndexPath) } } }, completion: nil) } else { // Detailed change information is not available; // repopulate the UI from the current fetch result. self.collectionView.reloadData() } } }}
其他
源代码
Swift
参考资料
Photos Framework Reference
PHChange Class Reference
PHFetchResultChangeDetails Class Reference
文档修改记录
版权所有
CSDN:http://blog.csdn.net/y550918116j
GitHub:https://github.com/937447974/Blog
0 0
- Photos(PHFetchResultChangeDetails)
- photos
- Mariage Photos
- Photos(简介)
- Photos(PHObject)
- Photos(PHPhotoLibrary)
- Photos(PHAsset)
- Photos(PHCollection)
- Photos(PHAssetCollection)
- Photos(PHImageManager)
- Photos(PHCachingImageManager)
- Photos(PHChange)
- Photos(PHObjectChangeDetails)
- Photos(PHAssetChangeRequest)
- Photos(PHAssetCreationRequest)
- Photos(PHCollectionListChangeRequest)
- Photos(PHAssetCollectionChangeRequest)
- Photos(PHLivePhoto)
- Android 版本兼容
- UC/OS-II基础知识之中断
- git之多人协作
- Html5网页录音,js录音mp3
- [异常处理]class kafka.common.UnknownTopicOrPartitionException (kafka.server.ReplicaFetcherThread)
- Photos(PHFetchResultChangeDetails)
- 支持C++ 11代码规范的 android NDK 编译
- 表单提交-js代码
- java 中的多态的演示
- VirtualBox Host-Only CentOS7 Mac Windows vboxnet0 网络共享
- Nodejs源码分析之Console
- Java实现对MongoDB的AND、OR和IN操作
- Photos(PHObjectChangeDetails)
- redis主从同步配置和原理