【问题标题】:fetchAssetCollectionsWithType to only retrieve videosfetchAssetCollectionsWithType 仅检索视频
【发布时间】:2015-10-08 21:45:45
【问题描述】:

我正在努力在 iOS 中制作自定义图库视图 为此,我正在使用迄今为止效果很好的照片框架 我无法让它工作的一件事是获取结果以仅返回 VIDEOS

我试过了 let result = PHAssetCollection.fetchAssetCollectionsWithType(.Moment, subtype: .SmartAlbumVideos, options: nil) 但它仍在检索图像我想知道语法是否错误

感谢您的帮助

【问题讨论】:

    标签: ios swift ios8 photosframework


    【解决方案1】:

    好的,我找到了我的问题的答案 基本上我需要使用一个谓词,这基本上是说检索媒体类型为视频的资产,并按creationDate对其进行排序

    let allVideosOptions = PHFetchOptions()
    allVideosOptions.predicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.Video.rawValue)
    allVideosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    videos = PHAsset.fetchAssetsWithOptions(allVideosOptions)
    

    【讨论】:

    • 如果我只能在相同的代码中添加相机胶卷中的视频怎么办??
    【解决方案2】:

    这里是objective-c代码。

    PHFetchOptions* fetchOptions;
    
    // all photos
    fetchOptions = [[PHFetchOptions alloc] init];
    fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
    if( self.bOnlyVideo == YES ) {
        fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeVideo];
    } else if( self.bOnlyPhoto == YES ) {
        fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
    }
    self.allPhotos = [PHAsset fetchAssetsWithOptions:fetchOptions];
    [fetchOptions release], fetchOptions = nil;
    

    【讨论】:

      猜你喜欢
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 2015-09-26
      • 2010-12-30
      • 1970-01-01
      • 2013-09-30
      相关资源
      最近更新 更多