[10秒学会] - iOS <Photos/Photos.h>自定义相册
2017-01-11 16:59
471 查看
摘要: [10秒学会] - iOS <Photos/Photos.h>自定义相册
这个是完整swift版本Demo: https://github.com/dacaizhao/swiftCameraAlbum
效果图:
点击屏幕 不同坐标显示图片
上代码:
这个是完整swift版本Demo: https://github.com/dacaizhao/swiftCameraAlbum
效果图:
点击屏幕 不同坐标显示图片
上代码:
// // ViewController.m // DCphoto // // Created by point on 16/5/12. // Copyright © 2016年 tshiny. All rights reserved. // #import "ViewController.h" #import <Photos/Photos.h> #import "UIView+YL.h" @interface ViewController () @property(nonatomic,strong) NSMutableArray *imgViewArr; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _imgViewArr = [NSMutableArray array]; [self searchAllImages]; // Do any additional setup after loading the view, typically from a nib. } - (void)searchAllImages { // 判断授权状态 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if (status != PHAuthorizationStatusAuthorized) return; dispatch_async(dispatch_get_main_queue(), ^{ // 遍历所有的自定义相册 PHFetchResult<PHAssetCollection *> *collectionResult0 = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; for (PHAssetCollection *collection in collectionResult0) { [self searchAllImagesInCollection:collection]; } // 获得相机胶卷的图片 PHFetchResult<PHAssetCollection *> *collectionResult1 = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; for (PHAssetCollection *collection in collectionResult1) { if (![collection.localizedTitle isEqualToString:@"Camera Roll"]) continue; [self searchAllImagesInCollection:collection]; break; } }); }]; } - (void)searchAllImagesInCollection:(PHAssetCollection *)collection { // 采取同步获取图片(只获得一次图片) PHImageRequestOptions *imageOptions = [[PHImageRequestOptions alloc] init]; imageOptions.synchronous = YES; NSLog(@"相册名字:%@", collection.localizedTitle); // 遍历这个相册中的所有图片 PHFetchResult<PHAsset *> *assetResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil]; for (PHAsset *asset in assetResult) { // 过滤非图片 if (asset.mediaType != PHAssetMediaTypeImage) continue; // 图片原尺寸 CGSize targetSize = CGSizeMake(asset.pixelWidth, asset.pixelHeight); // 请求图片 [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:targetSize contentMode:PHImageContentModeDefault options:imageOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { int width = [UIScreen mainScreen].bounds.size.width; int height = [UIScreen mainScreen].bounds.size.height; CGFloat x = (arc4random() % width) + 0; CGFloat y = (arc4random() % height) + 0; UIImageView * iView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, 100, 100)]; [self.view addSubview:iView]; iView.image = result; [_imgViewArr addObject:iView]; // NSLog(@"图片:%@ %@", result, [NSThread currentThread]); }]; } } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { for (UIImageView * img in _imgViewArr) { int width = [UIScreen mainScreen].bounds.size.width; int height = [UIScreen mainScreen].bounds.size.height; CGFloat x = (arc4random() % width) + 0; CGFloat y = (arc4random() % height) + 0; img.x = x; //这里 x y 需要坐标扩展 相信大家都知道 img.y = y; //!-_- } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- iOS:<Photos/Photos.h>获取相册视频以及图片
- iOS之相册新框架<Photos/Photos.h>
- Android UI设计之<二>自定义SwitchButton开关,实现类似IOS中UISwitch的动画效果
- <iOS>关于自定义description的一点用法
- iOS<Photos/Photos.h>与<AssetsLibrary/AssetsLibrary.h>and 相机
- ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高德地图,google地图)
- iOS:基于Photos框架的图片选择器以及创建自定义相册
- ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高德地图,google地图)
- ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高德地图,google地图)
- iOS 自定义相册和选取 AssetsLibrary 和 Photos(写的不错 一篇足以!感谢)
- ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高德地图,google地图)
- iOS 学会使用delegate和block<一>
- ios 一步一步学会自定义地图吹出框(CalloutView)-->(百度地图,高德地图,google地图)
- iOS 10 调用系统相册相机出现问题:-> 0x183a58d9c <+8>: b.lo 0x183a58db4 ; <+32>
- iOS自定义转场动画<转>
- 在Bundle中传递自定义的Arraylist<Object>
- iOS学习--uexiASIHTTPRequest使用指南---<<翻译稿>>
- Flex 自定义Tooltip 显示<s:datagrid>只显示行长标题的Tooltip
- 实现List<>自定义排序
- List<T>泛型数组API自带的Sort() 排序方法根据自定义排序实现