Unverified Commit dab94eaf authored by 谭真's avatar 谭真 Committed by GitHub

Merge pull request #702 from izemo/master

block内增加了强引用,防止因对象被释放而带来的异常
parents e70691b7 bfa91a0b
......@@ -56,7 +56,8 @@
_previewView.model = self.model;
__weak typeof(self) weakSelf = self;
[_previewView setSingleTapGestureBlock:^{
[weakSelf signleTapAction];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf signleTapAction];
}];
[self.view addSubview:_previewView];
}
......
......@@ -213,9 +213,11 @@
previewVc.currentIndex = index;
__weak typeof(self) weakSelf = self;
[previewVc setDoneButtonClickBlockWithPreviewType:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
[weakSelf dismissViewControllerAnimated:YES completion:^{
if (weakSelf.didFinishPickingPhotosHandle) {
weakSelf.didFinishPickingPhotosHandle(photos,assets,isSelectOriginalPhoto);
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf dismissViewControllerAnimated:YES completion:^{
if (!strongSelf) return;
if (strongSelf.didFinishPickingPhotosHandle) {
strongSelf.didFinishPickingPhotosHandle(photos,assets,isSelectOriginalPhoto);
}
}];
}];
......@@ -238,7 +240,8 @@
previewVc.currentIndex = 0;
__weak typeof(self) weakSelf = self;
[previewVc setDoneButtonClickBlockCropMode:^(UIImage *cropImage, id asset) {
[weakSelf dismissViewControllerAnimated:YES completion:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf dismissViewControllerAnimated:YES completion:^{
if (completion) {
completion(cropImage,asset);
}
......@@ -367,7 +370,8 @@
// if over time, dismiss HUD automatic
__weak typeof(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.timeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf hideProgressHUD];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf hideProgressHUD];
});
}
......
......@@ -460,10 +460,13 @@ static CGFloat itemMargin = 5;
__weak typeof(self) weakSelf = self;
__weak typeof(_numberImageView.layer) weakLayer = _numberImageView.layer;
cell.didSelectPhotoBlock = ^(BOOL isSelected) {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)weakSelf.navigationController;
__strong typeof(weakCell) strongCell = weakCell;
__strong typeof(weakSelf) strongSelf = weakSelf;
__strong typeof(weakLayer) strongLayer = weakLayer;
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)strongSelf.navigationController;
// 1. cancel select / 取消选择
if (isSelected) {
weakCell.selectPhotoButton.selected = NO;
strongCell.selectPhotoButton.selected = NO;
model.isSelected = NO;
NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels];
for (TZAssetModel *model_item in selectedModels) {
......@@ -472,20 +475,20 @@ static CGFloat itemMargin = 5;
break;
}
}
[weakSelf refreshBottomToolBarStatus];
[strongSelf refreshBottomToolBarStatus];
} else {
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) {
weakCell.selectPhotoButton.selected = YES;
strongCell.selectPhotoButton.selected = YES;
model.isSelected = YES;
[tzImagePickerVc.selectedModels addObject:model];
[weakSelf refreshBottomToolBarStatus];
[strongSelf refreshBottomToolBarStatus];
} else {
NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Select a maximum of %zd photos"], tzImagePickerVc.maxImagesCount];
[tzImagePickerVc showAlertWithTitle:title];
}
}
[UIView showOscillatoryAnimationWithLayer:weakLayer type:TZOscillatoryAnimationToSmaller];
[UIView showOscillatoryAnimationWithLayer:strongLayer type:TZOscillatoryAnimationToSmaller];
};
return cell;
}
......@@ -576,9 +579,11 @@ static CGFloat itemMargin = 5;
// 提前定位
__weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) {
weakSelf.location = location;
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location;
} failureBlock:^(NSError *error) {
weakSelf.location = nil;
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil;
}];
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
......@@ -613,16 +618,19 @@ static CGFloat itemMargin = 5;
__weak typeof(self) weakSelf = self;
photoPreviewVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
[photoPreviewVc setBackButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[weakSelf.collectionView reloadData];
[weakSelf refreshBottomToolBarStatus];
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[strongSelf.collectionView reloadData];
[strongSelf refreshBottomToolBarStatus];
}];
[photoPreviewVc setDoneButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[weakSelf doneButtonClick];
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[strongSelf doneButtonClick];
}];
[photoPreviewVc setDoneButtonClickBlockCropMode:^(UIImage *cropedImage, id asset) {
[weakSelf didGetAllPhotos:@[cropedImage] assets:@[asset] infoArr:nil];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf didGetAllPhotos:@[cropedImage] assets:@[asset] infoArr:nil];
}];
[self.navigationController pushViewController:photoPreviewVc animated:YES];
}
......
......@@ -50,13 +50,15 @@
self.previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self;
[self.previewView setSingleTapGestureBlock:^{
if (weakSelf.singleTapGestureBlock) {
weakSelf.singleTapGestureBlock();
__strong typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.singleTapGestureBlock) {
strongSelf.singleTapGestureBlock();
}
}];
[self.previewView setImageProgressUpdateBlock:^(double progress) {
if (weakSelf.imageProgressUpdateBlock) {
weakSelf.imageProgressUpdateBlock(progress);
__strong typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.imageProgressUpdateBlock) {
strongSelf.imageProgressUpdateBlock(progress);
}
}];
[self addSubview:self.previewView];
......@@ -419,7 +421,8 @@
_previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self;
[_previewView setSingleTapGestureBlock:^{
[weakSelf signleTapAction];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf signleTapAction];
}];
[self addSubview:_previewView];
}
......
......@@ -51,7 +51,6 @@
if (!self.models.count) {
self.models = [NSMutableArray arrayWithArray:_tzImagePickerVc.selectedModels];
_assetsTemp = [NSMutableArray arrayWithArray:_tzImagePickerVc.selectedAssets];
self.isSelectOriginalPhoto = _tzImagePickerVc.isSelectOriginalPhoto;
}
[self configCollectionView];
[self configCustomNaviBar];
......@@ -427,13 +426,17 @@
__weak typeof(_collectionView) weakCollectionView = _collectionView;
__weak typeof(photoPreviewCell) weakCell = photoPreviewCell;
[photoPreviewCell setImageProgressUpdateBlock:^(double progress) {
weakSelf.progress = progress;
__strong typeof(weakSelf) strongSelf = weakSelf;
__strong typeof(weakTzImagePickerVc) strongTzImagePickerVc = weakTzImagePickerVc;
__strong typeof(weakCollectionView) strongCollectionView = weakCollectionView;
__strong typeof(weakCell) strongCell = weakCell;
strongSelf.progress = progress;
if (progress >= 1) {
if (weakSelf.isSelectOriginalPhoto) [weakSelf showPhotoBytes];
if (weakSelf.alertView && [weakCollectionView.visibleCells containsObject:weakCell]) {
[weakTzImagePickerVc hideAlertView:weakSelf.alertView];
weakSelf.alertView = nil;
[weakSelf doneButtonClick];
if (strongSelf.isSelectOriginalPhoto) [strongSelf showPhotoBytes];
if (strongSelf.alertView && [strongCollectionView.visibleCells containsObject:strongCell]) {
[strongTzImagePickerVc hideAlertView:strongSelf.alertView];
strongSelf.alertView = nil;
[strongSelf doneButtonClick];
}
}
}];
......@@ -441,7 +444,8 @@
cell.model = model;
[cell setSingleTapGestureBlock:^{
[weakSelf didTapPreviewCell];
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf didTapPreviewCell];
}];
return cell;
}
......
......@@ -362,9 +362,11 @@
// 提前定位
__weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) {
weakSelf.location = location;
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location;
} failureBlock:^(NSError *error) {
weakSelf.location = nil;
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil;
}];
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
......
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