概述
iOS
PHCollectionListType
PHCollectionListSubtype
详解
typedef NS_ENUM(NSInteger, PHCollectionListType) {
PHCollectionListTypeMomentList = 1,//按照图片的时刻既时间进行分类
PHCollectionListTypeFolder = 2,//按照目录分类
PHCollectionListTypeSmartFolder = 3,//按照智能目录分类
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);
typedef NS_ENUM(NSInteger, PHCollectionListSubtype) {
// PHCollectionListTypeMomentList subtypes
PHCollectionListSubtypeMomentListCluster = 1,//按照族群分类
PHCollectionListSubtypeMomentListYear = 2,//按照年份分类
// PHCollectionListTypeFolder subtypes
PHCollectionListSubtypeRegularFolder = 100,
// PHCollectionListTypeSmartFolder subtypes
PHCollectionListSubtypeSmartFolderEvents = 200,
PHCollectionListSubtypeSmartFolderFaces = 201,
// Used for fetching if you don't care about the exact subtype
PHCollectionListSubtypeAny = NSIntegerMax
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);
在实际测试中发现PHCollectionListType 为PHCollectionListTypeFolder或PHCollectionListTypeSmartFolder使用如下方法测试 发现
都是空 这两个分类暂时不做分析 估计用处不大
那就分析PHCollectionListTypeMomentList这个
在PHCollectionListType为PHCollectionListTypeMomentList 分别测试PHCollectionListSubtype发现
PHCollectionListSubtypeMomentListCluster和PHCollectionListSubtypeMomentListYear有数据 并且数据相同
其他的都没有数据
可以发现对于list使用 PHCollectionListTypeMomentList 和 (PHCollectionListSubtypeMomentListCluster和PHCollectionListSubtypeMomentListYear)都行
就选第一个PHCollectionListSubtypeMomentListCluster吧。
/** 按照每天的数据对照片进行排序 */
- (void)getSystemContentImages{
// PHFetchResult *fetchResult = [PHCollectionList fetchMomentListsWithSubtype:PHCollectionListSubtypeAny options:nil ];
//
// PHFetchResult *collectionlists = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeSmartFolder subtype:PHCollectionListSubtypeAny options:nil];
// PHFetchResult *collectionlists1 = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeMomentList subtype:PHCollectionListSubtypeMomentListYear options:nil];
PHFetchResult *collectionlists1 = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeMomentList subtype:PHCollectionListSubtypeAny options:nil];
//NSArray *allLists = @[fetchResult, collectionlists, collectionlists1];
//NSArray *allLists = @[fetchResult];
NSArray *allLists = @[collectionlists1];
// NSArray *allLists = @[fetchResult];
for (PHFetchResult *fetchResultList in allLists) {
[fetchResultList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[PHCollectionList class]]) {
PHCollectionList *collectionList = (PHCollectionList *)obj;
[self phassetWithPHCollectionList:collectionList];
}
}];
}
// [fetchResults enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// if ([obj isKindOfClass:[PHCollectionList class]]) {
// PHCollectionList *collectionList = (PHCollectionList *)obj;
// [self phassetWithPHCollectionList:collectionList];
// }
// }];
}
- (void)phassetWithPHCollectionList:(PHCollectionList *)collectionList{
PHFetchResult<PHCollection *> *collections = [PHCollectionList fetchCollectionsInCollectionList:collectionList options:nil];
NSMutableArray<AssetsGroupModel *> *arrM = [NSMutableArray arrayWithCapacity:0];
for (id obj in collections) {
if ([obj isKindOfClass:[PHAssetCollection class]]) {
PHAssetCollection *assetCollection = (PHAssetCollection *)obj;
AssetsGroupModel *groupModel = [AssetsGroupModel new];
groupModel.groupName = assetCollection.localizedTitle;
NSLog(@"相簿名:%@", assetCollection.localizedTitle);
PHFetchResult<PHAsset *> *assetsFetchResults = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
[assetsFetchResults enumerateObjectsUsingBlock:^(PHAsset * _Nonnull asset, NSUInteger idx, BOOL * _Nonnull stop) {
// Photos library
UIScreen *screen = [UIScreen mainScreen];
CGFloat scale = screen.scale;
// Sizing is very rough... more thought required in a real implementation
//CGSize size = CGSizeMake(_asset.pixelWidth, _asset.pixelHeight);
CGFloat imageSize = MAX(screen.bounds.size.width, screen.bounds.size.height) * 1.5;
CGSize imageTargetSize = CGSizeMake(imageSize * scale, imageSize * scale);
AssetModel *model = [AssetModel assetWithPHAsset:asset targetSize:imageTargetSize];
[groupModel.assetsArrM addObject:model];
}];
[arrM addObject:groupModel];
}
}
//NSLog(@"arrM is %@", arrM);
}
最后
以上就是专一铃铛为你收集整理的iOS PHCollectionList详解的全部内容,希望文章能够帮你解决iOS PHCollectionList详解所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复