IOS进阶之AssetsLibrary.framework
来源:互联网 发布:淘宝网点击购买没反应 编辑:程序博客网 时间:2024/04/30 03:15
AssetsLibrary.framework
官方文档
是用来访问手机用户的媒体数据的框架,这里的媒体数据是指手机照片应用的图片,视频,livephto等
只支持到IOS9.0 ,9.0以后官方推荐使用Photo.framework
主要的类
ALAsset
照片应用的图片,视频,livephto等实例
ALAssetsFilter
提供了对一组ALAsset的滤镜行为
ALAssetsGroup
一组ALAsset,与照片应用的顺序是一一对应的
ALAssetsLibrary
提供了访问照片应用里图片,video,或者livephoto的方法
ALAssetRepresentation
ALAsset的表示和说明,包括UTI,尺寸规格,文件大小,方向,缩放比例,文件名等等
<span style="font-size:14px;">self.assetsLibrary = [[ALAssetsLibrary alloc] init]; dispatch_queue_t dispatchQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(dispatchQueue, ^(void) { // 遍历所有相册 [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { // 遍历每个相册中的项ALAsset [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop) { __block BOOL foundThePhoto = NO; if (foundThePhoto){ *stop = YES; } // ALAsset的类型 NSString *assetType = [result valueForProperty:ALAssetPropertyType]; if ([assetType isEqualToString:ALAssetTypePhoto]){ foundThePhoto = YES; *stop = YES; ALAssetRepresentation *assetRepresentation =[result defaultRepresentation]; CGFloat imageScale = [assetRepresentation scale]; UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation]; dispatch_async(dispatch_get_main_queue(), ^(void) { CGImageRef imageReference = [assetRepresentation fullResolutionImage]; // 对找到的图片进行操作 UIImage *image =[[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation]; if (image != nil){ //获取到第一张图片 } else { NSLog(@"Failed to create the image."); } }); } }]; } failureBlock:^(NSError *error) { NSLog(@"Failed to enumerate the asset groups."); }]; });</span>
下面利用第三方框架
写一个选择多张图片的demo
ZYQAssetPickerController下载
#import "MainViewController.h"#import "ZYQAssetPickerController.h"#import "AppDelegate.h"@interface MainViewController ()<ZYQAssetPickerControllerDelegate,UINavigationControllerDelegate,UIScrollViewDelegate>{ UIButton *btn; UIScrollView *src; UIPageControl *pageControl;}@end@implementation MainViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; btn=[[UIButton alloc] init]; btn.frame=CGRectMake(60., self.view.frame.size.height-80, self.view.frame.size.width-120, 60); [btn setTitle:@"Open" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [self.view addSubview:btn]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; src=[[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, self.view.frame.size.width-40, self.view.frame.size.height-120)]; src.pagingEnabled=YES; src.backgroundColor=[UIColor lightGrayColor]; src.delegate=self; [self.view addSubview:src]; pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(src.frame.origin.x, src.frame.origin.y+src.frame.size.height-20, src.frame.size.width, 20)]; [self.view addSubview:pageControl]; }-(void)btnClick:(id)sender{ ZYQAssetPickerController *picker = [[ZYQAssetPickerController alloc] init]; picker.maximumNumberOfSelection = 9; picker.assetsFilter = [ALAssetsFilter allPhotos]; picker.showEmptyGroups=NO; picker.delegate=self; picker.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { if ([[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypeVideo]) { NSTimeInterval duration = [[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyDuration] doubleValue]; return duration >= 5; } else { return YES; } }]; [self presentViewController:picker animated:YES completion:NULL];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - ZYQAssetPickerController Delegate-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{ [src.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ src.contentSize=CGSizeMake(assets.count*src.frame.size.width, src.frame.size.height); dispatch_async(dispatch_get_main_queue(), ^{ pageControl.numberOfPages=assets.count; }); for (int i=0; i<assets.count; i++) { ALAsset *asset=assets[i]; UIImageView *imgview=[[UIImageView alloc] initWithFrame:CGRectMake(i*src.frame.size.width, 0, src.frame.size.width, src.frame.size.height)]; imgview.contentMode=UIViewContentModeScaleAspectFill; imgview.clipsToBounds=YES; UIImage *tempImg=[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage]; dispatch_async(dispatch_get_main_queue(), ^{ [imgview setImage:tempImg]; [src addSubview:imgview]; }); } });}#pragma mark - UIScrollView Delegate-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ pageControl.currentPage=floor(scrollView.contentOffset.x/scrollView.frame.size.width);;}@end
0 0
- IOS进阶之AssetsLibrary.framework
- AssetsLibrary.framework
- IOS进阶之AudioToolBox.framework
- IOS进阶之AdSupport.framework
- IOS使用AssetsLibrary.Framework创建多图片选择控制器
- iOS 开发之照片框架详解之--AssetsLibrary
- iOS资源库AssetsLibrary
- IOS进阶之Accelebrate.framework 实现图片模糊效果
- iOS开发------简单实现图片多选功能(AssetsLibrary.framework篇)
- IOS 进阶Accounts.framework和Social.framework
- IOS AssetsLibrary框架的使用
- IOS AssetsLibrary框架的使用
- iOS开发AssetsLibrary的介绍
- AssetsLibrary
- AssetsLibrary
- iOS<Photos/Photos.h>与<AssetsLibrary/AssetsLibrary.h>and 相机
- iOS开发之:AssetsLibrary框架访问相册所有照片实现多选照片
- IOS进阶 AddressBook.framework和AddressBookUI.framework访问通讯录
- 安卓okhttp的封装
- 同态加密 Homomorphic Encryption
- linux mysql双机备份、双机热备、高可用
- http://blog.csdn.net/maomao171314
- Matlab连接MySQL小例
- IOS进阶之AssetsLibrary.framework
- canvas 状态的保存和恢复 Saving and restoring state
- redis主从数据库状态检测(php)
- Android图片异步加载之Android-Universal-Image-Loader
- UVaLive 3708 Graveyard (构造法求解最优化问题)
- 【html】表单控件禁用属性:readonly VS disabled
- Swift编程思想 Part 1 - 补遗:牺牲小马
- qss的简单使用
- 遍历二叉树的各种操作(非递归遍历)