Commit 28fb3ac5 authored by tanzhen's avatar tanzhen

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

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