PHCollectionList

作者: Shmily落墨 | 来源:发表于2017-05-05 22:14 被阅读105次

    包含了一组Photos资源集合的表现形式,例如一个时刻中的“年”或者用户创建的相簿文件夹。

    一、概述

    Photos框架中,集合对象(包括资源集合)不能直接引用它们自己内部的成员对象,并且也没有其他的对象能够直接引用集合对象。想要调用一个集合列表中的成员,请使用PHCollection的类方法获取,例如+ (PHFetchResult<PHCollection *> *)fetchCollectionsInCollectionList:(PHCollectionList *)collectionList options:(PHFetchOptions *)options;。想要在集合列表的顶层(例如一个没有上级文件夹的相簿文件夹)中查找一个对象,请使用+ (PHFetchResult<PHCollection *> *)fetchTopLevelUserCollectionsWithOptions:(PHFetchOptions *)options;方法。

    资源以及资源集合一样,集合列表也是不可以被修改的。想要创建、重命名、删除一个集合列表,或者想要添加、删除、重置集合列表中的内容,请在PHPhotoLibrary中的更改回调中创建一个PHCollectionListChangeRequest对象。想要获得更多关于更改请求以及更改回调的内容,清查看PHPhotoLibrary

    二、内容

    1. 获取集合列表

    + (PHFetchResult<PHCollectionList *> *)fetchCollectionListsContainingCollection:(PHCollection *)collection options:(nullable PHFetchOptions *)options;

    获取包含给定的集合集合列表
    不同类型的集合有可能被包含在不同的东西中。例如,一个PHAssetCollectionTypeAlbum类型的资源集合可能被包含在一个文件夹中,而不是在一个集合列表中。一个文件夹也有可能被包含在另一个文件夹中。一个PHAssetCollectionTypeMoment类型的资源集合总是被包含在两个集合列表中:一个“当前”时刻,一个“年”时刻

    + (PHFetchResult<PHCollectionList *> *)fetchCollectionListsWithLocalIdentifiers:(NSArray<NSString *> *)identifiers options:(nullable PHFetchOptions *)options;

    根据给定的本地设备唯一标识获取对应的集合列表

    + (PHFetchResult<PHCollectionList *> *)fetchCollectionListsWithType:(PHCollectionListType)collectionListType subtype:(PHCollectionListSubtype)subtype options:(nullable PHFetchOptions *)options;

    获取给定类型的集合列表

    PHCollectionListType

    typedef NS_ENUM(NSInteger, PHCollectionListType) {
        PHCollectionListTypeMomentList    = 1, // 包含了PHAssetCollectionTypeMoment类型的资源集合的列表
        PHCollectionListTypeFolder        = 2, // 包含了PHAssetCollectionTypeAlbum类型或PHAssetCollectionTypeSmartAlbum类型的资源集合的列表
        PHCollectionListTypeSmartFolder   = 3, // 同步到设备的智能文件夹的列表
    } PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);
    

    PHCollectionListSubtype

    typedef NS_ENUM(NSInteger, PHCollectionListSubtype) {
        // PHCollectionListTypeMomentList的子类型
        PHCollectionListSubtypeMomentListCluster    = 1, // 时刻
        PHCollectionListSubtypeMomentListYear       = 2, // 年度
        // PHCollectionListTypeFolder的子类型
        PHCollectionListSubtypeRegularFolder        = 100, // 包含了其他文件夹或者相簿的文件夹
        // PHCollectionListTypeSmartFolder的子类型
        PHCollectionListSubtypeSmartFolderEvents    = 200, // 包含了一个或多个从iPhone同步的事件的智能文件夹
        PHCollectionListSubtypeSmartFolderFaces     = 201, // 包含了一个或多个从iPhone同步的面孔(人物)的智能文件夹
        // 如果你不关心子类型是什么,则使用下面这个
        PHCollectionListSubtypeAny = NSIntegerMax
    } PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);
    
    + (PHFetchResult<PHCollectionList *> *)fetchMomentListsWithSubtype:(PHCollectionListSubtype)momentListSubtype containingMoment:(PHAssetCollection *)moment options:(nullable PHFetchOptions *)options;

    获取给定类型的并且包含给定的时刻集合列表

    + (PHFetchResult<PHCollectionList *> *)fetchMomentListsWithSubtype:(PHCollectionListSubtype)momentListSubtype options:(nullable PHFetchOptions *)options;

    获取给定类型的集合列表

    2. 获取集合列表数据

    @property (nonatomic, assign, readonly) PHCollectionListType collectionListType;

    The type of asset collection group that the collection list represents.
    A collection list may represent an upper level of the Moments hierarchy shown in the Photos app, a folder that contains albums, or a smart folder synced from iPhoto. See PHCollectionListType.

    @property (nonatomic, assign, readonly) PHCollectionListSubtype collectionListSubtype;

    The type of asset collection grouping the collection list represents.
    Use subtypes to make minor distinctions between collection lists of the same type, such as moment clusters and moment years. See PHCollectionListSubtype.

    @property (nonatomic, strong, readonly, nullable) NSDate *startDate;

    集合列表中所有资源中最早的一个的创建日期。
    这个属性只对类型为PHCollectionListTypeMomentList集合列表有效,对于其他的类型的集合列表这个属性的值为nil

    @property (nonatomic, strong, readonly, nullable) NSDate *endDate;

    集合列表中所有资源中最近的一个的创建日期。
    这个属性只对类型为PHCollectionListTypeMomentList集合列表有效,对于其他的类型的集合列表这个属性的值为nil

    @property (nonatomic, strong, readonly) NSArray<NSString *> *localizedLocationNames;

    一组集合定位地点的名字。
    对于一组时刻集合列表,正如你在照片应用中看到的那样,这个属性列出了这一组时刻中的定位地点的名字。对于其他类型的集合列表,这个属性的值为nil

    3. 创建临时集合列表

    + (PHCollectionList *)transientCollectionListWithCollections:(NSArray<PHCollection *> *)collections title:(nullable NSString *)title;

    创建一个包含了给定的资源集合集合列表

    + (PHCollectionList *)transientCollectionListWithCollectionsFetchResult:(PHFetchResult<PHCollection *> *)fetchResult title:(nullable NSString *)title;

    创一个包含了给定的获取结果中的资源集合集合列表

    相关文章

      网友评论

        本文标题:PHCollectionList

        本文链接:https://www.haomeiwen.com/subject/tneqtxtx.html