Git Product home page Git Product logo

banchichen / tzimagepickercontroller Goto Github PK

View Code? Open in Web Editor NEW
8.0K 8.0K 1.9K 6.93 MB

一个支持多选、选原图和视频的图片选择器,同时有预览、裁剪功能,支持iOS6+。 A clone of UIImagePickerController, support picking multiple photos、original photo、video, also allow preview photo and video, support iOS6+

License: MIT License

Objective-C 99.59% Ruby 0.18% Swift 0.23%
imagepicker imagepickercontroller imagepickerview photokit uiimagepickercontroller videopicker

tzimagepickercontroller's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tzimagepickercontroller's Issues

[UIApplication sharedApplication]优化

建议[UIApplication sharedApplication]相关的全局变量,在viewWillAppear的时候设置并备份原始的配置,viewDidDisappear的时候还原

除了楼上说的问题外还有两点问题我觉得也需要修复一下

  1. 如果设置imagePicker.allowPickingVideo = NO;
    在相机胶卷中就不应该出现视频,应该过滤掉。
  2. 选择两张图片后,进入预览,在预览界面再将两张图片取消选中,确定按钮可以点击,点击后会选择一张图片(应该一张图片都没有。)

3.还有一点:
在getPhotoWithAsset:photoWidth:completion:函数中,
CGImageRef thumbnailImageRef = alAsset.aspectRatioThumbnail;这句如果在ios6.0平台,缩略图会很模糊,感觉改为:CGImageRef thumbnailImageRef = alAsset.thumbnail;比较合适。

图片选中状态

你好,我想把图片的选中状态加到里面,就是选完图片再进去的时候可以看到我之前选中了哪些图片,

您好,当已经选取图片后 会显示一个hud 这时候 点击左上角的返回 hud不会消失

当然这是我们的测试人员发现的问题,实在是不好意思,又提了一个小小的问题 我的做法是加了一个小方法 真的感谢您!

代码修改的是这里
@implementation TZAlbumPickerController

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
    [imagePickerVc mt_hideProgressHUD];

    if (_albumArr) return;
    [self configTableView];
    }

  • (void)mt_hideProgressHUD {
    if (_progressHUD) {
    [_HUDIndicatorView stopAnimating];
    [_progressHUD removeFromSuperview];
    }
    }

UIView+Layout Category引起冲突

由于您在UIView+Layout这个Category中定义了UIView的left、top等属性,与Mansory(封装Autolayout的框架)中定义产生了冲突,导致我不得不重构您的代码来使用

建议不要采用这个Category,或者将里面的属性改为较复杂的名称。因为在多组件运用的工程中很容易出现类似的冲突,而兼容性是您的组件需要考虑的问题

最后多谢您的分享,期待您在下个版本中修复此问题

BUG

TZImageManager.m文件

/// Get photo bytes 获得一组照片的大小
- (void)getPhotosBytesWithArray:(NSArray *)photos completion:(void (^)(NSString *totalBytes))completion {
__block NSInteger dataLength = 0;
for (NSInteger i = 0; i < photos.count; i++) {
    TZAssetModel *model = photos[i];
    if ([model.asset isKindOfClass:[PHAsset class]]) {
        [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
            if (model.type != TZAssetModelMediaTypeVideo) dataLength += imageData.length;
            if (i >= photos.count - 1) {
                NSString *bytes = [self getBytesFromDataLength:dataLength];
                if (completion) completion(bytes);
            }
        }];
    } else if ([model.asset isKindOfClass:[ALAsset class]]) {
        ALAssetRepresentation *representation = [model.asset defaultRepresentation];
        if (model.type != TZAssetModelMediaTypeVideo) dataLength += (NSInteger)representation.size;
        if (i >= photos.count - 1) {
            NSString *bytes = [self getBytesFromDataLength:dataLength];
            if (completion) completion(bytes);
        }
    }
}
}

这样写有问题,由于requestImageDataForAsset默认是异步调用,当选择多张图片的时候,我们无法判断哪个请求先完成,假如选了5张图片,第五张求完成了,但是可能第一张请求还未完成,所以得到的照片大小和出错。
你可以采用手动开子线程,然后同步调用requestImageDataForAsset,比如:

+ (void)requestImageDataForAsset:(NSArray<PHAsset *>*)assets resultHandle:(void(^)(NSString * length))resultHandler{
 __block NSInteger totleLength = 0;
//采用组队列,判断请求是否全部完成
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.synchronous = YES;
    for (int i = 0 ;  i < assets.count; i++) {
        [[PHImageManager defaultManager] requestImageDataForAsset:assets[i] options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
            totleLength += imageData.length;
        }];
    }
});
dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSString *bytes;
    if (totleLength >= 0.1 * (1024 * 1024)) {
        bytes = [NSString stringWithFormat:@"%0.1fM",totleLength/1024/1024.0];
    } else if (totleLength >= 1024) {
        bytes = [NSString stringWithFormat:@"%0.0fK",totleLength/1024.0];
    } else {
        bytes = [NSString stringWithFormat:@"%zdB",totleLength];
    }
    //回到主线程刷新页面
    dispatch_async(dispatch_get_main_queue(), ^{
        resultHandler(bytes);
    });
});
}

多次选图片,可以超过九张

这个图片选择的时候,第一次选八张,发表界面预览8张,第二次选超过1张,发表界面就回超过9张,
你的picker没有记录总选择数应该9张,选过之后,应该记录还剩几张还能选,不然就会出现上述问题

bug

bug:
1.presentViewController的时候不会自动跳转到相机胶卷里,但是你的demo可以,看了下里面的代码实现,是根据名字来匹配的,这里面有坑。
2.demo里面将imagePickerVc.allowPickingVideo =NO;
设置成只能选图片之后,跳转出来的依旧可以选择视频

建议将NavigationController滑动返回的手势加上

选取原图有点问题

点击选取原图,但我去看大小的时候,没变化,是不是只点击原图只看得到原图大小,而拿到的还是编辑过的图,希望能看到并回复我一下

大神,你的工程中TZPhotoPickerController.m类存在内存泄漏不释放的情况,我纠正的代码如下

//
// TZPhotoPickerController.m
// TZImagePickerController
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
//

import "TZPhotoPickerController.h"

import "TZImagePickerController.h"

import "TZPhotoPreviewController.h"

import "TZAssetCell.h"

import "TZAssetModel.h"

import "UIView+Layout.h"

import "TZImageManager.h"

import "TZVideoPlayerController.h"

@interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@Property (nonatomic, strong) NSMutableArray *selectedPhotoArr;
@Property (nonatomic, strong) UICollectionView *collectionView;
@Property (nonatomic, strong) NSMutableArray *photoArr;
@Property (nonatomic, strong) UIButton *previewButton;
@Property (nonatomic, strong) UIButton *okButton;
@Property (nonatomic, strong) UIImageView *numberImageView;
@Property (nonatomic, strong) UILabel *numberLable;
@Property (nonatomic, strong) UIButton *originalPhotoButton;
@Property (nonatomic, strong) UILabel *originalPhotoLable;

@Property (nonatomic, assign) BOOL isSelectOriginalPhoto;
@Property (nonatomic, assign) BOOL shouldScrollToBottom;
@EnD

@implementation TZPhotoPickerController

  • (NSMutableArray *)selectedPhotoArr {
    if (_selectedPhotoArr == nil) _selectedPhotoArr = [NSMutableArray array];
    return _selectedPhotoArr;
    }

  • (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"## %s",FUNCTION);
    _shouldScrollToBottom = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _model.name;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    * __weak typeof (self)weakSelf=self;*
    TZImagePickerController _imagePickerVc = (TZImagePickerController *)self.navigationController;
    [[TZImageManager manager] getAssetsFromFetchResult:_model.result allowPickingVideo:imagePickerVc.allowPickingVideo completion:^(NSArray<TZAssetModel *> *models) {
    weakSelf.photoArr = [NSMutableArray arrayWithArray:models];
    [_weakSelf* configCollectionView];
    [weakSelf configBottomToolBar];
    }];
    }

  • (void)configCollectionView {

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat margin = 4;
    CGFloat itemWH = (self.view.width - 2 * margin - 4) / 4 - margin;
    layout.itemSize = CGSizeMake(itemWH, itemWH);
    layout.minimumInteritemSpacing = margin;
    layout.minimumLineSpacing = margin;
    CGFloat top = margin + 44;
    if (iOS7Later) top += 20;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(margin, top, self.view.width - 2 * margin, self.view.height - 50 - top) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.alwaysBounceHorizontal = NO;
    if (iOS7Later) self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 2);
    self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2);
    self.collectionView.contentSize = CGSizeMake(self.view.width, ((self.model.count + 3) / 4) * self.view.width);
    [self.view addSubview:self.collectionView];
    [self.collectionView registerNib:[UINib nibWithNibName:@"TZAssetCell" bundle:nil] forCellWithReuseIdentifier:@"TZAssetCell"];
    }

  • (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (_shouldScrollToBottom && _photoArr.count > 0) {
    [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:(_photoArr.count - 1) inSection:0] atScrollPosition:UICollectionViewScrollPositionBottom animated:NO];
    _shouldScrollToBottom = NO;
    }
    }

  • (void)configBottomToolBar {
    UIView *bottomToolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - 50, self.view.width, 50)];
    CGFloat rgb = 253 / 255.0;
    bottomToolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];

    _previewButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _previewButton.frame = CGRectMake(10, 3, 44, 44);
    [_previewButton addTarget:self action:@selector(previewButtonClick) forControlEvents:UIControlEventTouchUpInside];
    _previewButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_previewButton setTitle:@"预览" forState:UIControlStateNormal];
    [_previewButton setTitle:@"预览" forState:UIControlStateDisabled];
    [_previewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_previewButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
    _previewButton.enabled = NO;

    TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
    if (imagePickerVc.allowPickingOriginalPhoto) {
    _originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _originalPhotoButton.frame = CGRectMake(50, self.view.height - 50, 130, 50);
    _originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -8, 0, 0);
    _originalPhotoButton.contentEdgeInsets = UIEdgeInsetsMake(0, -45, 0, 0);
    [_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
    _originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_originalPhotoButton setTitle:@"原图" forState:UIControlStateNormal];
    [_originalPhotoButton setTitle:@"原图" forState:UIControlStateSelected];
    [_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_originalPhotoButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [_originalPhotoButton setImage:[UIImage imageNamed:@"photo_original_def"] forState:UIControlStateNormal];
    [_originalPhotoButton setImage:[UIImage imageNamed:@"photo_original_sel"] forState:UIControlStateSelected];
    _originalPhotoButton.enabled = _selectedPhotoArr.count > 0;

    _originalPhotoLable = [[UILabel alloc] init];
    _originalPhotoLable.frame = CGRectMake(70, 0, 60, 50);
    _originalPhotoLable.textAlignment = NSTextAlignmentLeft;
    _originalPhotoLable.font = [UIFont systemFontOfSize:16];
    _originalPhotoLable.textColor = [UIColor blackColor];
    if (_isSelectOriginalPhoto) [self getSelectedPhotoBytes];
    

    }

    _okButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _okButton.frame = CGRectMake(self.view.width - 44 - 12, 3, 44, 44);
    _okButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_okButton addTarget:self action:@selector(okButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_okButton setTitle:@"确定" forState:UIControlStateNormal];
    [_okButton setTitle:@"确定" forState:UIControlStateDisabled];
    [_okButton setTitleColor:kOKButtonTitleColorNormal forState:UIControlStateNormal];
    [_okButton setTitleColor:kOKButtonTitleColorDisabled forState:UIControlStateDisabled];
    _okButton.enabled = NO;

    _numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_number_icon"]];
    _numberImageView.frame = CGRectMake(self.view.width - 56 - 24, 12, 26, 26);
    _numberImageView.hidden = _selectedPhotoArr.count <= 0;
    _numberImageView.backgroundColor = [UIColor clearColor];

    _numberLable = [[UILabel alloc] init];
    _numberLable.frame = _numberImageView.frame;
    _numberLable.font = [UIFont systemFontOfSize:16];
    _numberLable.textColor = [UIColor whiteColor];
    _numberLable.textAlignment = NSTextAlignmentCenter;
    _numberLable.text = [NSString stringWithFormat:@"%zd",_selectedPhotoArr.count];
    _numberLable.hidden = _selectedPhotoArr.count <= 0;
    _numberLable.backgroundColor = [UIColor clearColor];

    UIView *divide = [[UIView alloc] init];
    CGFloat rgb2 = 222 / 255.0;
    divide.backgroundColor = [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0];
    divide.frame = CGRectMake(0, 0, self.view.width, 1);

    [bottomToolBar addSubview:divide];
    [bottomToolBar addSubview:_previewButton];
    [bottomToolBar addSubview:_okButton];
    [bottomToolBar addSubview:_numberImageView];
    [bottomToolBar addSubview:_numberLable];
    [self.view addSubview:bottomToolBar];
    [self.view addSubview:_originalPhotoButton];
    [_originalPhotoButton addSubview:_originalPhotoLable];
    }

pragma mark - Click Event

  • (void)cancel {
    TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
    if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
    [imagePickerVc.pickerDelegate imagePickerControllerDidCancel:imagePickerVc];
    }
    if (imagePickerVc.imagePickerControllerDidCancelHandle) {
    imagePickerVc.imagePickerControllerDidCancelHandle();
    }
    // [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
    }

  • (void)previewButtonClick {
    TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init];
    photoPreviewVc.photoArr = [NSArray arrayWithArray:self.selectedPhotoArr];
    [self pushPhotoPrevireViewController:photoPreviewVc];
    }

  • (void)originalPhotoButtonClick {
    _originalPhotoButton.selected = !_originalPhotoButton.isSelected;
    _isSelectOriginalPhoto = _originalPhotoButton.isSelected;
    _originalPhotoLable.hidden = !_originalPhotoButton.isSelected;
    if (_isSelectOriginalPhoto) [self getSelectedPhotoBytes];
    }

  • (void)okButtonClick {
    TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
    [imagePickerVc showProgressHUD];
    NSMutableArray *photos = [NSMutableArray array];
    NSMutableArray *assets = [NSMutableArray array];
    NSMutableArray *infoArr = [NSMutableArray array];

    for (NSInteger i = 0; i < _selectedPhotoArr.count; i++) {
    TZAssetModel *model = _selectedPhotoArr[i];
    [[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info) {

        if (photo)
        {
            CGFloat originScale=photo.size.width/photo.size.height;
            UIImage *scaleImage  =[ImgUtil compressImage:photo];
    
            #ifdef DEBUG
                NSInteger originLenght=[ImgUtil getImageSize:photo];
                NSLog(@"TZPhotoPickerController原图 image.scale:%f size:%ld width:%f height:%f",originScale,originLenght,photo.size.width,photo.size.height);
                NSInteger scaleLenght=[ImgUtil getImageSize:scaleImage];
                NSLog(@"TZPhotoPickerController压缩后图片 size:%ld width:%f height:%f",scaleLenght,scaleImage.size.width,scaleImage.size.height);
            #endif
    
            [photos addObject:scaleImage];
        }
        if (info) [infoArr addObject:info];
        if (_isSelectOriginalPhoto) [assets addObject:model.asset];
        if (photos.count < _selectedPhotoArr.count) return;
    
        if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingPhotos:sourceAssets:)]) {
            [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingPhotos:photos sourceAssets:assets];
        }
        if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingPhotos:sourceAssets:infos:)]) {
            [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingPhotos:photos sourceAssets:assets infos:infoArr];
        }
        if (imagePickerVc.didFinishPickingPhotosHandle) {
            imagePickerVc.didFinishPickingPhotosHandle(photos,assets);
        }
        if (imagePickerVc.didFinishPickingPhotosWithInfosHandle) {
            imagePickerVc.didFinishPickingPhotosWithInfosHandle(photos,assets,infoArr);
        }
        [imagePickerVc hideProgressHUD];
    }];
    

    }
    }

pragma mark - UICollectionViewDataSource && Delegate

  • (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _photoArr.count;
    }
  • (UICollectionViewCell _)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TZAssetCell cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZAssetCell" forIndexPath:indexPath];
    TZAssetModel model = _photoArr[indexPath.row];
    cell.model = model;
    _weak typeof(cell) weakCell = cell;
    *
    __weak typeof(self) weakSelf = self;

    cell.didSelectPhotoBlock = ^(BOOL isSelected) {
    // 1. cancel select / 取消选择
    if (isSelected) {
    weakCell.selectPhotoButton.selected = NO;
    model.isSelected = NO;
    [weakSelf.selectedPhotoArr removeObject:model];
    [weakSelf refreshBottomToolBarStatus];
    } else {
    // 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
    TZImagePickerController _imagePickerVc = (TZImagePickerController *)weakSelf.navigationController;
    if (weakSelf.selectedPhotoArr.count < imagePickerVc.maxImagesCount) {
    weakCell.selectPhotoButton.selected = YES;
    model.isSelected = YES;
    [_weakSelf.selectedPhotoArr* addObject:model];
    [weakSelf refreshBottomToolBarStatus];
    } else {
    [imagePickerVc showAlertWithTitle:[NSString stringWithFormat:@"你最多只能选择%zd张照片",imagePickerVc.maxImagesCount]];
    }
    }
    [UIView showOscillatoryAnimationWithLayer:weakSelf.numberImageView.layer type:TZOscillatoryAnimationToSmaller];
    };
    return cell;
    }
  • (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    TZAssetModel *model = _photoArr[indexPath.row];
    if (model.type == TZAssetModelMediaTypeVideo) {
    if (_selectedPhotoArr.count > 0) {
    TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
    [imagePickerVc showAlertWithTitle:@"选择照片时不能选择视频"];
    } else {
    TZVideoPlayerController *videoPlayerVc = [[TZVideoPlayerController alloc] init];
    videoPlayerVc.model = model;
    [self.navigationController pushViewController:videoPlayerVc animated:YES];
    }
    } else {
    TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init];
    photoPreviewVc.photoArr = _photoArr;
    photoPreviewVc.currentIndex = indexPath.row;
    [self pushPhotoPrevireViewController:photoPreviewVc];
    }
    }

pragma mark - Private Method

  • (void)refreshBottomToolBarStatus {
    _previewButton.enabled = self.selectedPhotoArr.count > 0;
    _okButton.enabled = self.selectedPhotoArr.count > 0;

    _numberImageView.hidden = _selectedPhotoArr.count <= 0;
    _numberLable.hidden = _selectedPhotoArr.count <= 0;
    _numberLable.text = [NSString stringWithFormat:@"%zd",_selectedPhotoArr.count];

    _originalPhotoButton.enabled = _selectedPhotoArr.count > 0;
    _originalPhotoButton.selected = (_isSelectOriginalPhoto && _originalPhotoButton.enabled);
    _originalPhotoLable.hidden = (!_originalPhotoButton.isSelected);
    if (_isSelectOriginalPhoto) [self getSelectedPhotoBytes];
    }

  • (void)pushPhotoPrevireViewController:(TZPhotoPreviewController *)photoPreviewVc {
    photoPreviewVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
    photoPreviewVc.selectedPhotoArr = self.selectedPhotoArr;
    photoPreviewVc.returnNewSelectedPhotoArrBlock = ^(NSMutableArray *newSelectedPhotoArr,BOOL isSelectOriginalPhoto) {
    _selectedPhotoArr = newSelectedPhotoArr;
    _isSelectOriginalPhoto = isSelectOriginalPhoto;
    [_collectionView reloadData];
    [self refreshBottomToolBarStatus];
    };
    photoPreviewVc.okButtonClickBlock = ^(NSMutableArray *newSelectedPhotoArr,BOOL isSelectOriginalPhoto){
    _selectedPhotoArr = newSelectedPhotoArr;
    _isSelectOriginalPhoto = isSelectOriginalPhoto;
    [self okButtonClick];
    };
    [self.navigationController pushViewController:photoPreviewVc animated:YES];
    }

  • (void)getSelectedPhotoBytes {
    [[TZImageManager manager] getPhotosBytesWithArray:_selectedPhotoArr completion:^(NSString *totalBytes) {
    _originalPhotoLable.text = [NSString stringWithFormat:@"(%@)",totalBytes];
    }];
    }

-(void)dealloc
{
NSLog(@"销毁%s",FUNCTION);
}

@EnD
// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com

代码小错误

TZPhotoPreviewController.m 中 cellForItemAtIndexPath 代理方法
__weak typeof(_naviBar) weakNaviBar = _naviBar; __weak typeof(_naviBar) weakToolBar = _naviBar;
写重了,应该是_toolBar。楼主写的很棒。辛苦了!

请教问题,非bug

请教一下, 怎么能和系统相册一样,按照时间顺序进行排列?

照片存储于iCloud时 下载失败

PHImageRequestOptions *option = [[PHImageRequestOptions alloc]init];
option.networkAccessAllowed = YES;

    [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(pixelWidth, pixelHeight) contentMode:PHImageContentModeAspectFit options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
        BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
        if (downloadFinined) {
            if (completion) completion(result,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]);
        }
    }];

PHImageRequestOptions 设置为 允许网络图片下载 就可以了

选择图片总数限制问题

比如我设置了limit=9 我先选择了7张图 然后返回 然后继续选择 可以选择大于9张 就能绕过9张图的限制

加载iCloud时灰屏

如果加载的图片是iCloud时,查看大图时是灰屏的,并且点击确认之后,那个加载指示器会一直存在视图上

crash , appearanceWhenContainedInInstancesOfClasses is available at 9.0

崩溃在TZImagePickerController类里的41行位置.
appearanceWhenContainedInInstancesOfClasses"这个方法是9.0之后才有的,但是你的判断却是让它在7.0之后的系统上执行,所以才导致崩溃

UIBarButtonItem *barItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];

1.0.7版本选择时报错

在pod下

添加方法后运行出现如下错误

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <xxx.app> (loaded)' with name 'TZAlbumCell''

报错地方

TZAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TZAlbumCell"];

猜测

检查了下nib的名字和imagepiccontroller 中引用的名字,没有错误,难道是其他问题引起的?

pods集成无法运行了

我用pods集成的 项目开启就蹦了 - - 问题是我还没调用你的 只是单纯的集成而已 它蹦的信息是这个
dyld`dyld_fatal_error: -> 0x120069098 <+0>: brk

但是手动集成就没有事

pod集成失败

用的swift,集成后所有XIB/图片资源打包进 TZImagePickerController.framework 中

但是运行时会只在 app 根目录下寻找资源,导致找不到资源而崩溃

cpu爆炸

滑动的时候明显卡顿,cpu飙到一百多

发送原图并不是原图

第一是修正转向的时候导致图片重绘,丢失了原来拍照的exif信息,第二是重绘之后图片尺寸变大了很多

正在处理。。。等太久

正在处理。。。等太久,然后那个提示框就一直在那了,也去不了了,我那边的代码应该也没耗时那么长啊,还有imagePickerControllerDidCancel这个方法名重复了?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.