iOS中图片与视频一次性多选
2012-12-21 00:58 v2m 阅读(3036) 评论(1) 编辑 收藏 举报一.使用系统的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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架