|
|
@@ -151,7 +151,6 @@ static CGFloat itemMargin = 5;
|
|
|
[self configCollectionView];
|
|
|
self->_collectionView.hidden = YES;
|
|
|
[self configBottomToolBar];
|
|
|
- [self refreshBottomToolBarStatus];
|
|
|
[self prepareScrollCollectionViewToBottom];
|
|
|
});
|
|
|
}
|
|
|
@@ -176,7 +175,7 @@ static CGFloat itemMargin = 5;
|
|
|
|
|
|
- (void)configCollectionView {
|
|
|
if (!_collectionView) {
|
|
|
- _layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
+ _layout = [TZCommonTools tz_rtlFlowLayout];
|
|
|
_collectionView = [[TZCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
|
|
|
if (@available(iOS 13.0, *)) {
|
|
|
_collectionView.backgroundColor = UIColor.tertiarySystemBackgroundColor;
|
|
|
@@ -204,18 +203,23 @@ static CGFloat itemMargin = 5;
|
|
|
|
|
|
_collectionView.contentSize = CGSizeMake(self.view.tz_width, (([self getAllCellCount] + self.columnNumber - 1) / self.columnNumber) * self.view.tz_width);
|
|
|
if (_models.count == 0) {
|
|
|
- _noDataLabel = [UILabel new];
|
|
|
+ [_collectionView addSubview:self.noDataLabel];
|
|
|
+ } else if (_noDataLabel) {
|
|
|
+ [_noDataLabel removeFromSuperview];
|
|
|
+ _noDataLabel = nil;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (UILabel *)noDataLabel {
|
|
|
+ if (!_noDataLabel) {
|
|
|
+ _noDataLabel = [[UILabel alloc] initWithFrame:_collectionView.bounds];
|
|
|
_noDataLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
_noDataLabel.text = [NSBundle tz_localizedStringForKey:@"No Photos or Videos"];
|
|
|
CGFloat rgb = 153 / 256.0;
|
|
|
_noDataLabel.textColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
|
|
|
_noDataLabel.font = [UIFont boldSystemFontOfSize:20];
|
|
|
- _noDataLabel.frame = _collectionView.bounds;
|
|
|
- [_collectionView addSubview:_noDataLabel];
|
|
|
- } else if (_noDataLabel) {
|
|
|
- [_noDataLabel removeFromSuperview];
|
|
|
- _noDataLabel = nil;
|
|
|
}
|
|
|
+ return _noDataLabel;
|
|
|
}
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
@@ -286,7 +290,7 @@ static CGFloat itemMargin = 5;
|
|
|
_originalPhotoButton.enabled = tzImagePickerVc.selectedModels.count > 0;
|
|
|
|
|
|
_originalPhotoLabel = [[UILabel alloc] init];
|
|
|
- _originalPhotoLabel.textAlignment = NSTextAlignmentLeft;
|
|
|
+ _originalPhotoLabel.textAlignment = NSTextAlignmentNatural;
|
|
|
_originalPhotoLabel.font = [UIFont systemFontOfSize:16];
|
|
|
if (@available(iOS 13.0, *)) {
|
|
|
_originalPhotoLabel.textColor = [UIColor labelColor];
|
|
|
@@ -365,8 +369,11 @@ static CGFloat itemMargin = 5;
|
|
|
CGFloat collectionViewHeight = 0;
|
|
|
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
|
|
|
CGFloat footerTipViewH = _authorizationLimited ? 80 : 0;
|
|
|
+
|
|
|
BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden;
|
|
|
BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height;
|
|
|
+ BOOL isRTL = [TZCommonTools tz_isRightToLeftLayout];
|
|
|
+
|
|
|
CGFloat toolBarHeight = 50 + [TZCommonTools tz_safeAreaInsets].bottom;
|
|
|
if (self.navigationController.navigationBar.isTranslucent) {
|
|
|
top = naviBarHeight;
|
|
|
@@ -405,16 +412,33 @@ static CGFloat itemMargin = 5;
|
|
|
if (!tzImagePickerVc.allowPreview) {
|
|
|
previewWidth = 0.0;
|
|
|
}
|
|
|
- _previewButton.frame = CGRectMake(10, 3, previewWidth, 44);
|
|
|
- _previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth;
|
|
|
+ previewWidth = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth;
|
|
|
+ if (isRTL) {
|
|
|
+ _previewButton.frame = CGRectMake(self.view.tz_width - previewWidth - 10, 3, previewWidth, 44);
|
|
|
+ } else {
|
|
|
+ _previewButton.frame = CGRectMake(10, 3, previewWidth, 44);
|
|
|
+ }
|
|
|
+
|
|
|
if (tzImagePickerVc.allowPickingOriginalPhoto) {
|
|
|
CGFloat fullImageWidth = [tzImagePickerVc.fullImageBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size.width;
|
|
|
- _originalPhotoButton.frame = CGRectMake(CGRectGetMaxX(_previewButton.frame), 0, fullImageWidth + 56, 50);
|
|
|
- _originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
|
|
|
+ if (isRTL) {
|
|
|
+ _originalPhotoButton.frame = CGRectMake(_previewButton.frame.origin.x - (fullImageWidth + 56), 0, fullImageWidth + 56, 50);
|
|
|
+ _originalPhotoLabel.frame = CGRectMake(-80 + 11, 0, 80, 50);
|
|
|
+ } else {
|
|
|
+ _originalPhotoButton.frame = CGRectMake(CGRectGetMaxX(_previewButton.frame), 0, fullImageWidth + 56, 50);
|
|
|
+ _originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
[_doneButton sizeToFit];
|
|
|
- _doneButton.frame = CGRectMake(self.view.tz_width - _doneButton.tz_width - 12, 0, MAX(44, _doneButton.tz_width), 50);
|
|
|
- _numberImageView.frame = CGRectMake(_doneButton.tz_left - 24 - 5, 13, 24, 24);
|
|
|
+ CGFloat donwButtonWidth = MAX(44, _doneButton.tz_width);
|
|
|
+ if (isRTL) {
|
|
|
+ _doneButton.frame = CGRectMake(12, 0, donwButtonWidth, 50);
|
|
|
+ _numberImageView.frame = CGRectMake(_doneButton.tz_right + 5, 13, 24, 24);
|
|
|
+ } else {
|
|
|
+ _doneButton.frame = CGRectMake(self.view.tz_width - donwButtonWidth - 12, 0, donwButtonWidth, 50);
|
|
|
+ _numberImageView.frame = CGRectMake(_doneButton.tz_left - 24 - 5, 13, 24, 24);
|
|
|
+ }
|
|
|
_numberLabel.frame = _numberImageView.frame;
|
|
|
_divideLine.frame = CGRectMake(0, 0, self.view.tz_width, 1);
|
|
|
|
|
|
@@ -793,7 +817,7 @@ static CGFloat itemMargin = 5;
|
|
|
UIAlertAction *cancelAct = [UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"Cancel"] style:UIAlertActionStyleCancel handler:nil];
|
|
|
[alertController addAction:cancelAct];
|
|
|
UIAlertAction *settingAct = [UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"Setting"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
|
|
|
}];
|
|
|
[alertController addAction:settingAct];
|
|
|
[self.navigationController presentViewController:alertController animated:YES completion:nil];
|
|
|
@@ -812,7 +836,7 @@ static CGFloat itemMargin = 5;
|
|
|
}
|
|
|
|
|
|
- (void)openSettingsApplication {
|
|
|
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
|
|
|
}
|
|
|
|
|
|
- (void)addMorePhoto {
|
|
|
@@ -961,16 +985,12 @@ static CGFloat itemMargin = 5;
|
|
|
[selectedAssets addObject:model.asset];
|
|
|
}
|
|
|
// 拿到了最新的models,在此刷新照片选中状态
|
|
|
- // 由于可能有照片权限变化,也需要刷新selectedModels https://github.com/banchichen/TZImagePickerController/pull/1658
|
|
|
- NSMutableArray *newSelectedModels = [NSMutableArray array];
|
|
|
for (TZAssetModel *model in _models) {
|
|
|
model.isSelected = NO;
|
|
|
if ([selectedAssets containsObject:model.asset]) {
|
|
|
model.isSelected = YES;
|
|
|
- [newSelectedModels addObject:model];
|
|
|
}
|
|
|
}
|
|
|
- tzImagePickerVc.selectedModels = newSelectedModels;
|
|
|
}
|
|
|
|
|
|
/// 选中/取消选中某张照片
|
|
|
@@ -1110,10 +1130,14 @@ static CGFloat itemMargin = 5;
|
|
|
PHFetchResultChangeDetails *changeDetail = [changeInstance changeDetailsForFetchResult:self.model.result];
|
|
|
if (changeDetail == nil) return;
|
|
|
if ([[TZImageManager manager] isPHAuthorizationStatusLimited]) {
|
|
|
- self.model.result = changeDetail.fetchResultAfterChanges;
|
|
|
- self.model.count = changeDetail.fetchResultAfterChanges.count;
|
|
|
- [self fetchAssetModels];
|
|
|
- } else if (changeDetail.hasIncrementalChanges == NO) {
|
|
|
+ NSArray *changedObjects = [changeDetail changedObjects];
|
|
|
+ changeDetail = [PHFetchResultChangeDetails changeDetailsFromFetchResult:self.model.result toFetchResult:changeDetail.fetchResultAfterChanges changedObjects:changedObjects];
|
|
|
+ if (changeDetail && changeDetail.removedObjects.count) {
|
|
|
+ [self handleRemovedAssets:changeDetail.removedObjects];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (changeDetail.hasIncrementalChanges == NO) {
|
|
|
[self.model refreshFetchResult];
|
|
|
[self fetchAssetModels];
|
|
|
} else {
|
|
|
@@ -1129,6 +1153,21 @@ static CGFloat itemMargin = 5;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+- (void)handleRemovedAssets:(NSArray<PHAsset *> *)removedObjects {
|
|
|
+ TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
|
|
|
+ for (PHAsset *asset in removedObjects) {
|
|
|
+ Boolean isSelected = [tzImagePickerVc.selectedAssetIds containsObject:asset.localIdentifier];
|
|
|
+ if (!isSelected) continue;
|
|
|
+ NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels];
|
|
|
+ for (TZAssetModel *model_item in selectedModels) {
|
|
|
+ if ([asset.localIdentifier isEqualToString:model_item.asset.localIdentifier]) {
|
|
|
+ [tzImagePickerVc removeSelectedModel:model_item];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ [self refreshBottomToolBarStatus];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Asset Caching
|
|
|
|
|
|
- (void)resetCachedAssets {
|