Commit 28fb3ac5 authored by tanzhen's avatar tanzhen

修复block造成循环引用导致内存泄露的问题

parent 71b420ef
Pod::Spec.new do |s|
s.name = "TZImagePickerController"
s.version = "1.0.5"
s.version = "1.0.6"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT"
s.author = { "banchichen" => "736420282@qq.com" }
s.platform = :ios
s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.0.5" }
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.0.6" }
s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/Resource/*.{png,xib,nib}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
......@@ -90,6 +90,7 @@
[self pushToPhotoPickerVc];
[_tipLable removeFromSuperview];
[_timer invalidate];
_timer = nil;
}
}
......@@ -155,6 +156,8 @@
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (iOS7Later) viewController.automaticallyAdjustsScrollViewInsets = NO;
if (_timer) { [_timer invalidate]; _timer = nil;}
if (self.childViewControllers.count > 0) {
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 0, 44, 44)];
[backButton setImage:[UIImage imageNamed:@"navi_back"] forState:UIControlStateNormal];
......
......@@ -231,27 +231,30 @@
TZAssetCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZAssetCell" forIndexPath:indexPath];
TZAssetModel *model = _photoArr[indexPath.row];
cell.model = model;
typeof(cell) weakCell = cell;
__weak typeof(cell) weakCell = cell;
__weak typeof(self) weakSelf = self;
__weak typeof(_numberImageView.layer) weakLayer = _numberImageView.layer;
cell.didSelectPhotoBlock = ^(BOOL isSelected) {
// 1. cancel select / 取消选择
if (isSelected) {
weakCell.selectPhotoButton.selected = NO;
model.isSelected = NO;
[self.selectedPhotoArr removeObject:model];
[self refreshBottomToolBarStatus];
[weakSelf.selectedPhotoArr removeObject:model];
[weakSelf refreshBottomToolBarStatus];
} else {
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (self.selectedPhotoArr.count < imagePickerVc.maxImagesCount) {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)weakSelf.navigationController;
if (weakSelf.selectedPhotoArr.count < imagePickerVc.maxImagesCount) {
weakCell.selectPhotoButton.selected = YES;
model.isSelected = YES;
[self.selectedPhotoArr addObject:model];
[self refreshBottomToolBarStatus];
[weakSelf.selectedPhotoArr addObject:model];
[weakSelf refreshBottomToolBarStatus];
} else {
[imagePickerVc showAlertWithTitle:[NSString stringWithFormat:@"你最多只能选择%zd张照片",imagePickerVc.maxImagesCount]];
}
}
[UIView showOscillatoryAnimationWithLayer:_numberImageView.layer type:TZOscillatoryAnimationToSmaller];
[UIView showOscillatoryAnimationWithLayer:weakLayer type:TZOscillatoryAnimationToSmaller];
};
return cell;
}
......
......@@ -124,5 +124,4 @@
self.imageContainerView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX, scrollView.contentSize.height * 0.5 + offsetY);
}
@end
......@@ -234,12 +234,16 @@
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TZPhotoPreviewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZPhotoPreviewCell" forIndexPath:indexPath];
cell.model = _photoArr[indexPath.row];
__block BOOL _weakIsHideNaviBar = _isHideNaviBar;
__weak typeof(_naviBar) weakNaviBar = _naviBar;
__weak typeof(_naviBar) weakToolBar = _naviBar;
if (!cell.singleTapGestureBlock) {
cell.singleTapGestureBlock = ^(){
// show or hide naviBar / 显示或隐藏导航栏
_isHideNaviBar = !_isHideNaviBar;
_naviBar.hidden = _isHideNaviBar;
_toolBar.hidden = _isHideNaviBar;
_weakIsHideNaviBar = !_weakIsHideNaviBar;
weakNaviBar.hidden = _weakIsHideNaviBar;
weakToolBar.hidden = _weakIsHideNaviBar;
};
}
return cell;
......
......@@ -79,6 +79,7 @@
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets) {
}];
[self presentViewController:imagePickerVc animated:YES completion:nil];
}
......@@ -87,7 +88,7 @@
/// User click cancel button
/// 用户点击了取消
- (void)imagePickerControllerDidCancel:(TZImagePickerController *)picker {
NSLog(@"cancel");
// NSLog(@"cancel");
}
/// User finish picking photo,if assets are not empty, user picking original photo.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment