Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

初始化同一个ZLPhotoActionSheet,预览图片后再打开图库异常 —— 2.6.4版本已解决 #184

Closed
adntian opened this issue Jan 16, 2018 · 18 comments

Comments

@adntian
Copy link

adntian commented Jan 16, 2018

重现步骤:
1.初始化ZLPhotoActionSheet
2.调用showPhotoLibrary 添加图片到 UIImageView
3.点击 UIImageVIew 预览图片
4.再次调用showPhotoLibrary添加图片时,会出现异常
image

问题应该是没有清空 arrSelectedModels
多数地方都有调用
[self.arrSelectedModels removeAllObjects];
这里应该也需要调用一下吧?

我加了断点在下面的方法看到打开的 UIImage 不是同一个地址

(NSMutableArray<ZLPhotoModel *> *)arrSelectedModels

补充一下
- (void)showPreview:(BOOL)preview animate:(BOOL)animate

    if (!self.configuration.allowSelectImage && self.arrSelectedModels.count) {
        [self.arrSelectedAssets removeAllObjects];
        [self.arrSelectedModels removeAllObjects];
    }

上述操作后,这里self.configuration.allowSelectImage为 YES,self.arrSelectedModels.count为1

@adntian
Copy link
Author

adntian commented Jan 16, 2018

我使用的是只能选择一张图片,不显示多选框;

如果我在 vc 中保存和传递的是NSArray<PHAsset *> * _Nonnull assets这个变量的话,是不会出现异常的
但打开之后,选择图片界面出现了多选框(不能选择其它图片)
image

@longitachi
Copy link
Owner

我按照你描述的步骤测试了下demo,并没有出现异常啊。 出现选择框,你有没有设置最大选择数为1?还有就是你当前cocoapods版本是多少?

@adntian
Copy link
Author

adntian commented Jan 16, 2018

2.6.3

            ZLPhotoActionSheet *ac = [ZLPhotoActionSheet new];
            ac.configuration.maxSelectCount = 1;
            ac.configuration.maxPreviewCount = 10;
            ac.configuration.saveNewImageAfterEdit = NO;
            ac.configuration.allowMixSelect = NO;
            ac.configuration.allowSelectGif = NO;
            ac.configuration.allowRecordVideo = NO;
            ac.configuration.allowSelectVideo = NO;
            ac.configuration.useSystemCamera = YES;
            ac.configuration.showSelectBtn = NO;
            ac.configuration.navBarColor = CNavBgColor;
            ac.configuration.navTitleColor = CNavBgFontColor;
            ac.sender = self;
            [ac setSelectImageBlock:^(NSArray<UIImage *> * _Nullable images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
                //传递图片给 view :images[0]
            }];
            [ac showPhotoLibrary];


            // 下面是预览的调用 image 是从 UIImageView 中取过来
            [ac previewPhotos:@[image] index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {}];

@adntian
Copy link
Author

adntian commented Jan 16, 2018

出现选择框是用了下面这个预览的
[ac previewPhotos:self.assets index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {}];

@longitachi
Copy link
Owner

。。。我用demo,第二次进去还是不显示选择按钮。你现在的问题不是在相册界面显示了选择框吗?

@adntian
Copy link
Author

adntian commented Jan 16, 2018

我的问题是在最前面,会崩溃

@adntian
Copy link
Author

adntian commented Jan 16, 2018

出现选择框是我在调试时遇到的(不算问题)

@adntian
Copy link
Author

adntian commented Jan 16, 2018

好的,我再测试一下,晚上回来回复结果

@longitachi
Copy link
Owner

崩溃我这边也没遇到,你先用demo测试下,看能不能重现?

@adntian
Copy link
Author

adntian commented Jan 16, 2018

#import "ViewController.h"
#import <ZLPhotoBrowser/ZLPhotoActionSheet.h>

@interface ViewController ()
@property (nonatomic, weak) UIImageView *imgview;
@property (nonatomic, strong) ZLPhotoActionSheet *ac;
@property (nonatomic, strong) NSArray<PHAsset *> *assets;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setView];
}

- (void)setView {
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton new];
    [btn setTitle:@"先点添加" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.frame = CGRectMake(50, 100, 80, 20);
    [btn addTarget:self action:@selector(addClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    UIButton *btn1 = [UIButton new];
    [btn1 setTitle:@"预览后点添加会崩溃" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn1.frame = CGRectMake(120, 100, 200, 20);
    [btn1 addTarget:self action:@selector(preview) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    UIButton *btn2 = [UIButton new];
    [btn2 setTitle:@"预览后点添加出现选择框" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn2.frame = CGRectMake(120, 130, 250, 20);
    [btn2 addTarget:self action:@selector(preview2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    UIImageView *imgview = [UIImageView new];
    imgview.frame = CGRectMake(100, 200, 200, 200);
    [self.view addSubview:imgview];
    _imgview = imgview;
    [self getac];
}

- (void)getac {
    ZLPhotoActionSheet *ac = [ZLPhotoActionSheet new];
    ac.configuration.maxSelectCount = 1;
    ac.configuration.maxPreviewCount = 10;
    ac.configuration.saveNewImageAfterEdit = NO;
    ac.configuration.allowMixSelect = NO;
    ac.configuration.allowSelectGif = NO;
    ac.configuration.allowRecordVideo = NO;
    ac.configuration.allowSelectVideo = NO;
    ac.configuration.useSystemCamera = YES;
    ac.configuration.showSelectBtn = NO;
    ac.sender = self;
    self.ac = ac;
}


- (void)addClick {
    __weak typeof(self) weakself = self;
    [_ac setSelectImageBlock:^(NSArray<UIImage *> * _Nullable images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
        weakself.imgview.image = images[0];
        weakself.assets = assets;
    }];
    [_ac showPhotoLibrary];
}

- (void)preview {
    if (self.assets == nil) {
        return;
    }
    // 这个是重现选择框的问题,不会出现崩溃
    [_ac previewPhotos:self.assets index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {}];
}

- (void)preview2 {
    if (self.imgview.image == nil) {
        return;
    }
    // 这个是会出现崩溃的
    [_ac previewPhotos:@[self.imgview.image] index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {}];
}

重现步骤
1.点添加按钮
2.点预览按钮
3.点添加按钮

@adntian
Copy link
Author

adntian commented Jan 16, 2018

Installing ZLPhotoBrowser (2.6.3)

@longitachi
Copy link
Owner

longitachi commented Jan 17, 2018

我知道原因了,你那边崩溃是因为把 ZLPhotoActionSheet 的对象声明成了类属性,预览后导致arrSelectedModels对象发生变化,所以导致了这个,我看下解决下这个bug

@adntian
Copy link
Author

adntian commented Jan 17, 2018

预览时传递 UIImage 数组的时候会出现这个问题
传递PHAsset数组不会崩溃,会出现选择框(这个选择框也是为了标记当前选中的图片,应该是需要的)

@longitachi
Copy link
Owner

这个选择框是不该出现的。。。因为最大选择数量为1,如果设置了showSelectBtn=NO就不会显示这个的,这个算是bug,我会修复后,更新下版本

@adntian
Copy link
Author

adntian commented Jan 17, 2018

好的

@MRZHL
Copy link

MRZHL commented Jan 17, 2018

同样遇见了这个问题, 预览之后, 再去图库选择照片崩溃 [selIdentifiers addObject:m.asset.localIdentifier]; 在这里.

@MRZHL
Copy link

MRZHL commented Jan 17, 2018

我的解决办法是初始化了两个ZLPhotoActionSheet 一个用来预览 一个用来选择照片

@longitachi
Copy link
Owner

等会会更新下版本

longitachi added a commit that referenced this issue Jan 17, 2018
@longitachi longitachi changed the title 初始化同一个ZLPhotoActionSheet,预览图片后再打开图库异常 初始化同一个ZLPhotoActionSheet,预览图片后再打开图库异常 —— 2.6.4版本已解决 Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants