• iOS开发:iOS中图片与视频一次性多选


    一.使用系统的Assets Library Framework
    这个是用来访问Photos程序中的图片和视频的库。其中几个类解释如下
      ALAsset
        ->包含一个图片或视频的各种信息

      ALAssetRepresentation
        ->得到ALAsset的各种信息

      ALAssetsFilter
        ->用来从一个ALAssetsGroup中检索ALAssets

      ALAssetsGroup
        ->一组ALAsset,一个asset可以属于多个这样的组,可以添加一个asset到某个组中

      ALAssetsLibrary
        ->整个图片库中的内容,可以对图片库的获取与编辑等

      网上有人说这种方法会要求授权地理位置信息,不过我没有遇到...

    看看官方的使用示例,枚举的时候以nil结束哦,记得判断处理下。

    // The following example shows how you can get an asset to represent the first video in the Saved Photos Album.
    
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    
    // Within the group enumeration block, filter to enumerate just videos.
    [group setAssetsFilter:[ALAssetsFilter allVideos]];
    
    // For this example, we're only interested in the first item.
    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
    options:0
    usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
    
    // The end of the enumeration is signaled by asset == nil.
    if (alAsset) {
    ALAssetRepresentation *representation = [alAsset defaultRepresentation];
    NSURL *url = [representation url];
    AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
    // Do something interesting with the AV asset.
    }
    }];
    }
    failureBlock: ^(NSError *error) {
    // Typically you should handle an error more gracefully than this.
    NSLog(@"No groups");
    }];
    
    [library release];

    二.网络上的另一种方法-MHImagePickerMutilSelector
    这个是通过设置UINavigationControllerDelegate的方法,当UIImagePickerController显示在界面上的时候,判断一下当前是图集列表(相当于AlAssetsGroup的列表)还是图片列表(相当于AlAsset的列表),如果是图片列表就调整scrollview的大小,并在下面加上一个自己的滚动视图用来显示已经选择的图片。

    这个方法的缺点是对已经选择的图片做点自定义的动作相对而言比较麻烦。

    我稍微修改了下^_^(仅仅是稍微,让它调用的时候简单了点,对重复图片什么的也没有处理)

    使用时只要UIVIewController实现了 MHImagePickerMutilSelector的协议,然后这样调用就好了。

    [MHImagePickerMutilSelector showInViewController:self];

    这里下载。

    参考:http://www.cocoachina.com/bbs/read.php?tid=112242

  • 相关阅读:
    在一台Linux服务器上安装多个MySQL实例(二)--使用单独的MySQL配置文件
    在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式
    MySQL复制(四)--多源(主)复制
    MySQL复制(三)--基于全局事物标识符(GTID)配置复制
    类加载机制详解
    字符串常量池理解
    JVM内存模型
    Java设计模式之单例模式
    forkjoin及其性能分析,是否比for循环快?
    集合排序Comparable和Comparator有什么区别?
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/3177724.html
Copyright © 2020-2023  润新知