先放上效果图
设计思路
先获取到按照时间分类的相册集合,再利用CollectionView来展示获取到的图片,然后通过pan手势识别触摸区域内的子Cell。判断子Cell是选中还是取消。下面是具体实现步骤
#获取图片资源
利用PHCollectionList,获取到一个时刻集合。通过指定它的subType从而获取到以天为单位的时刻集合momentList。然后在遍历这个momentList的集合,从而获取里面的PHAssetCollection资源集合。然后从PHAssetCollection资源集合中取出相应的资源文件PHAsset,得到每天的照片数量。
通过以上方法我们就可以得到一个二维数组 Array[日期][具体照片]。完整实现代码如下
NSMutableArray* momentArray = [NSMutableArray array];
PHFetchOptions *momentOptions = [[PHFetchOptions alloc]init];
momentOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"startDate" ascending:NO]];
PHFetchResult* collectionList = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeMomentList subtype:PHCollectionListSubtypeMomentListCluster options:momentOptions];
[collectionList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//创建一个时刻存放数组
PHCollectionList* momentList = (PHCollectionList*) obj;
NSMutableArray* dayArray = [NSMutableArray array];
//获取时刻里面的Asset集合