iOS - 多选相册
来源:互联网 发布:linux网络编程看什么书 编辑:程序博客网 时间:2024/05/29 17:43
//
// FirViewController.m
// 多选Demo
//
#import "ShowViewController.h"
#import "NSObject+YFPhoto.h"
#import "YFShowGroupAlbumVC.h"
#import "ShowCell.h"
#import "YFSelfImage.h"
#import "ALAssetsLibrary+YF.h"
#import <AssetsLibrary/AssetsLibrary.h>
#define K_WIDTH [UIScreen mainScreen].bounds.size.width
#define K_HEIGHT [UIScreen mainScreen].bounds.size.height
static NSString *const FIRCELL = @"ShowCell";
@interface ShowViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>
{
NSMutableArray *imageArray;//数组
YFShowGroupAlbumVC *showVC;//显示相册分组的控制器
UINavigationController *navShow;//因为相册分组是模态出来的,所以给他一个导航,让相册详细界面可以导航出来
}
@property(nonatomic,strong)showBigImage *showView;//大图
//左边按钮
- (IBAction)clickLeftBtn:(id)sender;
//右边按钮
- (IBAction)clickBtn:(id)sender;
@property (weak,nonatomic) IBOutletUICollectionView *collectionView;
@end
@implementation ShowViewController
- (void)viewDidLoad {
[superviewDidLoad];
imageArray = [NSMutableArrayarray];
showVC = [[YFShowGroupAlbumVCalloc]init];
navShow = [[UINavigationControlleralloc]initWithRootViewController:showVC];
[_collectionViewregisterNib:[UINibnibWithNibName:FIRCELLbundle:nil]forCellWithReuseIdentifier:FIRCELL];
_collectionView.backgroundColor = [UIColorwhiteColor];
[selfsetCollectionLayOut];
//接受通知一个是把宰相册详情选择的图片传过来,一个是把相机照的图片传过来
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(notShow:)name:@"pushImage"object:nil];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(saveImageSure:)name:@"SAVEIMAGE"object:nil];
}
/**
* 获得选中的图片数组
*
* @param user <#user description#>
*/
- (void)notShow:(NSNotification *)user{
[imageArrayremoveAllObjects];
NSDictionary *dic = user.userInfo;
[imageArrayaddObjectsFromArray:dic[@"cellImage"]];
[_collectionViewreloadData];
}
/**
* 获得相机图片
*
* @param user <#user description#>
*/
- (void)saveImageSure:(NSNotification *)user{
NSDictionary *dic = user.userInfo;
YFSelfImage *image = dic[@"saveImage"];
[imageArrayaddObject:image];
[_collectionViewreloadData];
}
/**
* 设置布局
*/
- (void)setCollectionLayOut{
UICollectionViewFlowLayout *layOut = [[UICollectionViewFlowLayoutalloc]init];
layOut.itemSize =CGSizeMake(K_WIDTH /3, K_WIDTH /3);
layOut.minimumLineSpacing =0;
layOut.minimumInteritemSpacing=0;
[_collectionViewsetCollectionViewLayout:layOut];
}
/**
* 左边按钮事件
*
* @param sender <#sender description#>
*/
- (IBAction)clickLeftBtn:(id)sender {
//弹出选择视图
UIActionSheet *sheet = [[UIActionSheetalloc]initWithTitle:@"选择方式"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"相机"otherButtonTitles:@"相册",nil];
[sheet showInView:self.view];
}
/**
* 右边按钮事件
*
* @param sender <#sender description#>
*/
- (IBAction)clickBtn:(id)sender {
showVC.showAlbumStyle =ENUM_PhotoAndCamera;
showVC.albumColor = [UIColorwhiteColor];
showVC.listCount =4;
[selfpresentViewController:navShowanimated:YEScompletion:nil];
}
#pragma mark actionSheet代理
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case0:
//打开相机
[selfshowCamera];
break;
case1:
//打开相册
showVC.showAlbumStyle =ENUM_AllOfPhoto;
showVC.albumColor = [UIColorwhiteColor];
showVC.listCount =5;
[selfpresentViewController:navShowanimated:YEScompletion:nil];
break;
case2:
NSLog(@"2");
break;
default:
break;
}
}
#pragma mark 九宫格代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
returnimageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
ShowCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:FIRCELLforIndexPath:indexPath];
cell.deleBtn.tag = indexPath.row;
//删除
__weaktypeof(self)weakSelf =self;
cell.deleBlock = ^(NSInteger index){
//删除数组中对应的元素
[imageArrayremoveObjectAtIndex:index];
[weakSelf.collectionViewreloadData];
};
YFSelfImage *image =imageArray[indexPath.row];
cell.imageView.image = image;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
YFSelfImage *image =imageArray[indexPath.row];
//获取图片的详细资源
ALAssetRepresentation *represention = [image.assetdefaultRepresentation];
//获取高清图
UIImage *bigImage = [[UIImagealloc]initWithCGImage:[representionfullResolutionImage]];
//显示大图
if (!_showView) {
_showView = [[showBigImagealloc]initWithFrame:CGRectMake(0,64, K_WIDTH,K_HEIGHT - 64)];
_showView.bigImageView.image = bigImage;
_showView.alpha =1.0;
__weaktypeof(self)weakSelf =self;
_showView.hiddenBlock = ^{
weakSelf.showView.alpha =0.0;
};
[self.viewaddSubview:_showView];
}else{
_showView.bigImageView.image = bigImage;
_showView.alpha =1.0;
}
}
- (void)dealloc{
[[NSNotificationCenterdefaultCenter]removeObserver:self];
}
@end
/***************************大图显示view******************************/
@implementation showBigImage
- (instancetype)initWithFrame:(CGRect)frame{
self = [superinitWithFrame:frame];
if (self) {
_bigImageView = [[UIImageViewalloc]initWithFrame:self.bounds];
[selfaddSubview:_bigImageView];
_bigImageView.userInteractionEnabled =YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(hiddenView)];
[self.bigImageViewaddGestureRecognizer:tap];
}
returnself;
}
- (void)hiddenView{
if (self.hiddenBlock) {
self.hiddenBlock();
}
}
@end
- iOS - 多选相册
- iOS相册多选照片
- iOS相册多选照片
- iOS 自定义多选相册
- iOS自定义相册多选控件制作
- IOS开发—自定义多选相册
- iOS 相册多选 相机选择图片
- iOS 相册多选图片上传
- iOS相册选图实现
- 【iOS】拍照/相册单选、相册多选、图片浏览、图片裁剪
- iOS 相册
- # iOS 相册图片多选以及类似微信获取相册图片并使用AFN框架上传至服务器
- IOS 系统相册 选取多张
- iOS开发---Swift相册框架,实现相片多选、反选等功能
- iOS开发之:AssetsLibrary框架访问相册所有照片实现多选照片
- ios 使用ELCImagePicker实现相册照片多选和真机拍照调试
- iOS 使用photokit框架获取系统相册,实现多选,全选。
- IOS相册功能
- c++中的 extern "C"
- 获取微信接口调用凭据AccessToken
- 12.2
- 减小apk体积二
- [Linux笔记001]:jdk及eclipse安装
- iOS - 多选相册
- spring data jpa 条件分页查询
- 子线程循环 3 次,接着主线程循环 6 次,接着又回到子线程循环 3 次,接着再回到主线程又循环6 次,如此循环50次。
- PopupWindow概述
- response.setContentType()的作用及参数
- 十四周 项目1-验证算法(折半查找)
- 第13周项目5-拓扑排序算法的验证
- [Linux笔记002]:显示隐藏文件和链接
- 第14周项目1-(2)验证分块查找算法