CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Feb 2018 |
Maintained by LoveZYForever.
pod 'HXWeiboPhotoPicker' '~> 2.1.2'
搜索不到库或最新版请执行pod repo update
SDWebImage v4.0.0
// 懒加载 照片管理类
- (HXPhotoManager *)manager {
if (!_manager) {
_manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
}
return _manager;
}
// 照片选择控制器
HXPhotoViewController *vc = [[HXPhotoViewController alloc] init];
vc.delegate = self;
vc.manager = self.manager;
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
// 通过 HXPhotoViewControllerDelegate 代理返回选择的图片以及视频
- (void)photoViewControllerDidNext:(NSArray *)allList Photos:(NSArray *)photos Videos:(NSArray *)videos Original:(BOOL)original
// 点击取消
- (void)photoViewControllerDidCancel
// 懒加载 照片管理类
- (HXPhotoManager *)manager {
if (!_manager) {
_manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
}
return _manager;
}
self.navigationController.navigationBar.translucent = NO;
self.automaticallyAdjustsScrollViewInsets = YES;
HXPhotoView *photoView = [[HXPhotoView alloc] initWithFrame:CGRectMake((414 - 375) / 2, 100, 375, 400) manager:self.manager];
photoView.delegate = self;
photoView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:photoView];
// 代理返回 选择、移动顺序、删除之后的图片以及视频
- (void)photoView:(HXPhotoView *)photoView changeComplete:(NSArray<HXPhotoModel *> *)allList photos:(NSArray<HXPhotoModel *> *)photos videos:(NSArray<HXPhotoModel *> *)videos original:(BOOL)isOriginal;
// 当view更新高度时调用
- (void)photoView:(HXPhotoView *)photoView updateFrame:(CGRect)frame;
// 删除网络图片的地址
- (void)photoView:(HXPhotoView *)photoView deleteNetworkPhoto:(NSString *)networkPhotoUrl;
// 网络图片全部下载完成时调用
- (void)photoViewAllNetworkingPhotoDownloadComplete:(HXPhotoView *)photoView;
- (HXPhotoManager *)manager { // 懒加载管理类
if (!_manager) { // 设置一些配置信息
_manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhoto];
// _manager.openCamera = NO;
_manager.outerCamera = YES;
_manager.showDeleteNetworkPhotoAlert = NO;
_manager.saveSystemAblum = YES;
_manager.photoMaxNum = 2; // 这里需要注意 !!! 第一次传入的最大照片数 是可选最大数 减去 网络照片数量 即 photoMaxNum = maxNum - networkPhotoUrls.count 当点击删除网络照片时, photoMaxNum 内部会自动加1
_manager.videoMaxNum = 0; // 如果有网络图片且选择类型为HXPhotoManagerSelectedTypePhotoAndVideo 又设置了视频最大数且不为0时,
// 那么在选择照片列表最大只能选择 photoMaxNum + videoMaxNum
// 在外面collectionView上最大数是 photoMaxNum + networkPhotoUrls.count + videoMaxNum
_manager.maxNum = 6;
// 可以这个赋值也可以像下面那样
// _manager.networkPhotoUrls = [NSMutableArray arrayWithObjects:@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/003d86db-b140-4162-aafa-d38056742181.jpg",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/0034821a-6815-4d64-b0f2-09103d62630d.jpg",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/0be5118d-f550-403e-8e5c-6d0badb53648.jpg",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/1466408576222.jpg", nil];
}
return _manager;
}
CGFloat width = scrollView.frame.size.width;
HXPhotoView *photoView = [HXPhotoView photoManager:self.manager];
photoView.frame = CGRectMake(kPhotoViewMargin, kPhotoViewMargin, width - kPhotoViewMargin * 2, 0);
photoView.delegate = self;
photoView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:photoView];
self.photoView = photoView;
// 可以在懒加载中赋值 , 也可以这样赋值
self.manager.networkPhotoUrls = [NSMutableArray arrayWithObjects:@"http://oss-cn-hangzhou.aliyuncs.com/tsnrhapp/shop/photos/857980fd0acd3caf9e258e42788e38f5_0.gif",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/0034821a-6815-4d64-b0f2-09103d62630d.jpg",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/0be5118d-f550-403e-8e5c-6d0badb53648.jpg",@"http://tsnrhapp.oss-cn-hangzhou.aliyuncs.com/1466408576222.jpg", nil];
// 设置完网络图片地址数组后重新给manager赋值
photoView.manager = self.manager;
- (HXPhotoManager *)manager {
if (!_manager) {
_manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhoto];
_manager.openCamera = YES;
// 在这里设置为单选模式
_manager.singleSelected = YES;
// 设置是否需要裁剪功能
_manager.singleSelecteClip = NO;
_manager.cameraType = HXPhotoManagerCameraTypeFullScreen;
}
return _manager;
}
HXPhotoViewController *vc = [[HXPhotoViewController alloc] init];
vc.manager = self.manager;
vc.delegate = self;
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
// 代理返回选择的结果
- (void)photoViewControllerDidNext:(NSArray<HXPhotoModel *> *)allList Photos:(NSArray<HXPhotoModel *> *)photos Videos:(NSArray<HXPhotoModel *> *)videos Original:(BOOL)original {
__weak typeof(self) weakSelf = self;
// 这里使用HXPhotoTools 里面的方法获取image
[HXPhotoTools getImageForSelectedPhoto:photos type:0 completion:^(NSArray<UIImage *> *images) {
weakSelf.imageView.image = images.firstObject;
}];
}
// 懒加载三个管理类用来控制三个选择器
- (HXPhotoManager *)oneManager {
if (!_oneManager) {
_oneManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhoto];
}
return _oneManager;
}
- (HXPhotoManager *)twoManager {
if (!_twoManager) {
_twoManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypeVideo];
}
return _twoManager;
}
- (HXPhotoManager *)threeManager {
if (!_threeManager) {
_threeManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
}
return _threeManager;
}
// 初始化UIScrollerView以及三个HXPhotoView
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.scrollView.alwaysBounceVertical = YES;
[self.view addSubview:self.scrollView];
self.onePhotoView = [[HXPhotoView alloc] initWithFrame:CGRectMake(kPhotoViewMargin, kPhotoViewMargin, self.view.frame.size.width - kPhotoViewMargin * 2, 0) WithManager:self.oneManager];
self.onePhotoView.delegate = self;
[self.scrollView addSubview:self.onePhotoView];
self.twoPhotoView = [[HXPhotoView alloc] initWithFrame:CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.onePhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, 0) WithManager:self.twoManager];
self.twoPhotoView.delegate = self;
[self.scrollView addSubview:self.twoPhotoView];
self.threePhotoView = [[HXPhotoView alloc] initWithFrame:CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.twoPhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, 0) WithManager:self.threeManager];
self.threePhotoView.delegate = self;
[self.scrollView addSubview:self.threePhotoView];
// 根据photoView来判断是哪一个选择器
- (void)photoView:(HXPhotoView *)photoView changeComplete:(NSArray<HXPhotoModel *> *)allList photos:(NSArray<HXPhotoModel *> *)photos videos:(NSArray<HXPhotoModel *> *)videos original:(BOOL)isOriginal {
if (self.onePhotoView == photoView) {
NSSLog(@"onePhotoView - %@",allList);
}else if (self.twoPhotoView == photoView) {
NSSLog(@"twoPhotoView - %@",allList);
}else if (self.threePhotoView == photoView) {
NSSLog(@"threePhotoView - %@",allList);
}
}
// 返回更新后的frame,根据photoView来更新scrollView
- (void)photoView:(HXPhotoView *)photoView updateFrame:(CGRect)frame {
if (self.onePhotoView == photoView) {
self.twoPhotoView.frame = CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.onePhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, self.twoPhotoView.frame.size.height);
self.threePhotoView.frame = CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.twoPhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, self.threePhotoView.frame.size.height);
}else if (self.twoPhotoView == photoView) {
self.twoPhotoView.frame = CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.onePhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, self.twoPhotoView.frame.size.height);
self.threePhotoView.frame = CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.twoPhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, self.threePhotoView.frame.size.height);
}else if (self.threePhotoView == photoView) {
self.threePhotoView.frame = CGRectMake(kPhotoViewMargin, CGRectGetMaxY(self.twoPhotoView.frame) + kPhotoViewSectionMargin, self.view.frame.size.width - kPhotoViewMargin * 2, frame.size.height);
}
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(self.threePhotoView.frame) + kPhotoViewMargin);
}
// 先在第一个控制器里初始化管理类并设置好属性
- (HXPhotoManager *)manager {
if (!_manager) {
/** 注意!!! 如果是先选照片拍摄的话, 不支持将拍摄的照片或者视频保存到系统相册 **/
_manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
_manager.outerCamera = YES;
_manager.openCamera = NO;
_manager.saveSystemAblum = YES;
}
return _manager;
}
// 通过HXPhotoViewController的代理跳转界面并将当前界面的管理类传入下一个界面
- (void)photoViewControllerDidNext:(NSArray<HXPhotoModel *> *)allList Photos:(NSArray<HXPhotoModel *> *)photos Videos:(NSArray<HXPhotoModel *> *)videos Original:(BOOL)original {
Demo6SubViewController *vc = [[Demo6SubViewController alloc] init];
vc.manager = self.manager;
[self.navigationController pushViewController:vc animated:YES];
}
// 这里需要注意在第二个控制释放的时候需要将已选的操作清空
- (void)dealloc {
[self.manager clearSelectedList];
}
// 加载本地图片
NSMutableArray *images = [NSMutableArray array];
for (int i = 0 ; i < 4; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
[images addObject:image];
}
CGFloat width = scrollView.frame.size.width;
HXPhotoView *photoView = [[HXPhotoView alloc] initWithFrame:CGRectMake(kPhotoViewMargin, kPhotoViewMargin, width - kPhotoViewMargin * 2, 0) manager:self.manager];
photoView.delegate = self;
photoView.backgroundColor = [UIColor whiteColor];
// 在这里将本地图片image数组给管理类并且刷新界面
self.manager.localImageList = images;
[photoView refreshView];
[scrollView addSubview:photoView];
self.photoView = photoView;
后期计划(剔除微博样式、框架大改造、优化关于网络图片的部分、单选模式支持HXPhotoView)
如果您发现了bug请尽可能详细地描述系统版本、手机型号和复现步骤等信息 提一个issue.
如果您有什么好的建议也可以提issue,大家一起讨论一起学习进步...
具体代码请下载项目 如果觉得喜欢的能给一颗小星星么!