Skip to content

Commit

Permalink
适配阿拉伯等语言下从右往左布局的特性
Browse files Browse the repository at this point in the history
  • Loading branch information
banchichen committed Oct 8, 2018
1 parent 177778f commit 9434081
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 17 deletions.
7 changes: 7 additions & 0 deletions TZImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
9038D5901C3974F0007DE549 /* TZTestCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZTestCell.m; sourceTree = "<group>"; };
903996921F447604005E77C2 /* Photos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Photos.framework; path = System/Library/Frameworks/Photos.framework; sourceTree = SDKROOT; };
903996941F447609005E77C2 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; };
909DBC95216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "ar-001.lproj/Main.strings"; sourceTree = "<group>"; };
909DBC96216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "ar-001.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
909DBC97216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "../ar-001.lproj/Localizable.strings"; sourceTree = "<group>"; };
90A74B84203287C200D84C2A /* tz-ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "tz-ru"; path = Localizable.strings; sourceTree = "<group>"; };
90CE84AC1C3A89EF003D0779 /* TZImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZImageManager.h; sourceTree = "<group>"; };
90CE84AD1C3A89EF003D0779 /* TZImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZImageManager.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -498,6 +501,7 @@
Base,
"zh-Hans",
"tz-ru",
"ar-001",
);
mainGroup = 900E65731C2BB8D5003D9A9E;
productRefGroup = 900E657D1C2BB8D5003D9A9E /* Products */;
Expand Down Expand Up @@ -643,6 +647,7 @@
children = (
900E65891C2BB8D5003D9A9E /* Base */,
6D12FC191D66B71E00182C44 /* zh-Hans */,
909DBC95216B981B00926570 /* ar-001 */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand All @@ -652,6 +657,7 @@
children = (
900E658E1C2BB8D5003D9A9E /* Base */,
6D12FC1A1D66B71E00182C44 /* zh-Hans */,
909DBC96216B981B00926570 /* ar-001 */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
Expand All @@ -660,6 +666,7 @@
isa = PBXVariantGroup;
children = (
90A74B84203287C200D84C2A /* tz-ru */,
909DBC97216B981B00926570 /* ar-001 */,
);
name = Localizable.strings;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
+ (CGFloat)tz_statusBarHeight;
// 获得Info.plist数据字典
+ (NSDictionary *)tz_getInfoDictionary;
+ (BOOL)isRightToLeftLayout;
@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,21 @@ + (NSDictionary *)tz_getInfoDictionary {
}
return infoDict ? infoDict : @{};
}

+ (BOOL)isRightToLeftLayout {
if (@available(iOS 9.0, *)) {
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:UISemanticContentAttributeUnspecified] == UIUserInterfaceLayoutDirectionRightToLeft) {
return YES;
}
} else {
NSString *preferredLanguage = [NSLocale preferredLanguages].firstObject;
if ([preferredLanguage hasPrefix:@"ar-"]) {
return YES;
}
}
return NO;
}

@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ - (void)configBottomToolBar {

if (tzImagePickerVc.allowPickingOriginalPhoto) {
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, [TZCommonTools isRightToLeftLayout] ? 10 : -10, 0, 0);
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_originalPhotoButton setTitle:tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateNormal];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (void)viewDidLoad {
[self configCustomNaviBar];
[self configBottomToolBar];
self.view.clipsToBounds = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}

- (void)setIsSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
Expand All @@ -78,7 +78,9 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIApplication sharedApplication].statusBarHidden = YES;
if (_currentIndex) [_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * _currentIndex, 0) animated:NO];
if (_currentIndex) {
[_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * self.currentIndex, 0) animated:NO];
}
[self refreshNaviBarAndBottomBarState];
}

Expand Down Expand Up @@ -135,7 +137,7 @@ - (void)configBottomToolBar {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_tzImagePickerVc.allowPickingOriginalPhoto) {
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, [TZCommonTools isRightToLeftLayout] ? 10 : -10, 0, 0);
_originalPhotoButton.backgroundColor = [UIColor clearColor];
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:13];
Expand Down Expand Up @@ -242,7 +244,7 @@ - (void)configCropView {
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;

CGFloat statusBarHeight = [TZCommonTools tz_statusBarHeight];
CGFloat statusBarHeightInterval = statusBarHeight - 20;
CGFloat naviBarHeight = statusBarHeight + _tzImagePickerVc.navigationBar.tz_height;
Expand Down Expand Up @@ -294,7 +296,7 @@ - (void)didChangeStatusBarOrientationNotification:(NSNotification *)noti {

- (void)select:(UIButton *)selectButton {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
TZAssetModel *model = _models[_currentIndex];
TZAssetModel *model = _models[self.currentIndex];
if (!selectButton.isSelected) {
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if (_tzImagePickerVc.selectedModels.count >= _tzImagePickerVc.maxImagesCount) {
Expand All @@ -305,8 +307,8 @@ - (void)select:(UIButton *)selectButton {
} else {
[_tzImagePickerVc addSelectedModel:model];
if (self.photos) {
[_tzImagePickerVc.selectedAssets addObject:_assetsTemp[_currentIndex]];
[self.photos addObject:_photosTemp[_currentIndex]];
[_tzImagePickerVc.selectedAssets addObject:_assetsTemp[self.currentIndex]];
[self.photos addObject:_photosTemp[self.currentIndex]];
}
if (model.type == TZAssetModelMediaTypeVideo && !_tzImagePickerVc.allowPickingMultipleVideo) {
[_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Select the video when in multi state, we will handle the video as a photo"]];
Expand All @@ -331,13 +333,13 @@ - (void)select:(UIButton *)selectButton {
NSArray *selectedAssetsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedAssets];
for (NSInteger i = 0; i < selectedAssetsTmp.count; i++) {
id asset = selectedAssetsTmp[i];
if ([asset isEqual:_assetsTemp[_currentIndex]]) {
if ([asset isEqual:_assetsTemp[self.currentIndex]]) {
[_tzImagePickerVc.selectedAssets removeObjectAtIndex:i];
break;
}
}
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[_currentIndex]];
[self.photos removeObject:_photosTemp[_currentIndex]];
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[self.currentIndex]];
[self.photos removeObject:_photosTemp[self.currentIndex]];
}
break;
}
Expand Down Expand Up @@ -378,10 +380,10 @@ - (void)doneButtonClick {

// 如果没有选中过照片 点击确定时选中当前预览的照片
if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) {
TZAssetModel *model = _models[_currentIndex];
TZAssetModel *model = _models[self.currentIndex];
[_tzImagePickerVc addSelectedModel:model];
}
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.currentIndex inSection:0];
TZPhotoPreviewCell *cell = (TZPhotoPreviewCell *)[_collectionView cellForItemAtIndexPath:indexPath];
if (_tzImagePickerVc.allowCrop && [cell isKindOfClass:[TZPhotoPreviewCell class]]) { // 裁剪状态
_doneButton.enabled = NO;
Expand All @@ -393,7 +395,7 @@ - (void)doneButtonClick {
_doneButton.enabled = YES;
[_tzImagePickerVc hideProgressHUD];
if (self.doneButtonClickBlockCropMode) {
TZAssetModel *model = _models[_currentIndex];
TZAssetModel *model = _models[self.currentIndex];
self.doneButtonClickBlockCropMode(cropedImage,model.asset);
}
} else if (self.doneButtonClickBlock) { // 非裁剪状态
Expand Down Expand Up @@ -433,7 +435,6 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
offSetWidth = offSetWidth + ((self.view.tz_width + 20) * 0.5);

NSInteger currentIndex = offSetWidth / (self.view.tz_width + 20);

if (currentIndex < _models.count && _currentIndex != currentIndex) {
_currentIndex = currentIndex;
[self refreshNaviBarAndBottomBarState];
Expand Down Expand Up @@ -513,7 +514,7 @@ - (void)dealloc {

- (void)refreshNaviBarAndBottomBarState {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
TZAssetModel *model = _models[_currentIndex];
TZAssetModel *model = _models[self.currentIndex];
_selectButton.selected = model.isSelected;
[self refreshSelectButtonImageViewContentMode];
if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex && _tzImagePickerVc.showSelectBtn) {
Expand Down Expand Up @@ -567,9 +568,13 @@ - (void)refreshSelectButtonImageViewContentMode {
}

- (void)showPhotoBytes {
[[TZImageManager manager] getPhotosBytesWithArray:@[_models[_currentIndex]] completion:^(NSString *totalBytes) {
[[TZImageManager manager] getPhotosBytesWithArray:@[_models[self.currentIndex]] completion:^(NSString *totalBytes) {
self->_originalPhotoLabel.text = [NSString stringWithFormat:@"(%@)",totalBytes];
}];
}

- (NSInteger)currentIndex {
return [TZCommonTools isRightToLeftLayout] ? self.models.count - _currentIndex - 1 : _currentIndex;
}

@end
1 change: 1 addition & 0 deletions TZImagePickerController/ar-001.lproj/LaunchScreen.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
48 changes: 48 additions & 0 deletions TZImagePickerController/ar-001.lproj/Main.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

/* Class = "UITextField"; text = "9"; ObjectID = "37K-cO-hgf"; */
"37K-cO-hgf.text" = "9";

/* Class = "UILabel"; text = "允许选择照片原图"; ObjectID = "7mi-Lf-2N5"; */
"7mi-Lf-2N5.text" = "允许选择照片原图";

/* Class = "UILabel"; text = "允许多选视频/GIF/图片"; ObjectID = "7q9-aI-kbz"; */
"7q9-aI-kbz.text" = "允许多选视频/GIF/图片";

/* Class = "UILabel"; text = "允许拍视频"; ObjectID = "8H2-cq-aUq"; */
"8H2-cq-aUq.text" = "允许拍视频";

/* Class = "UILabel"; text = "单选模式下允许裁剪"; ObjectID = "Ibb-kN-MWC"; */
"Ibb-kN-MWC.text" = "单选模式下允许裁剪";

/* Class = "UILabel"; text = "允许选择Gif图片"; ObjectID = "Ly2-uJ-7DN"; */
"Ly2-uJ-7DN.text" = "允许选择Gif图片";

/* Class = "UILabel"; text = "允许拍照"; ObjectID = "R92-Zn-NWV"; */
"R92-Zn-NWV.text" = "允许拍照";

/* Class = "UILabel"; text = "使用圆形裁剪框"; ObjectID = "TiG-df-jDs"; */
"TiG-df-jDs.text" = "使用圆形裁剪框";

/* Class = "UILabel"; text = "照片按修改时间升序排列"; ObjectID = "UL3-n3-Hmt"; */
"UL3-n3-Hmt.text" = "照片按修改时间升序排列";

/* Class = "UITextField"; text = "4"; ObjectID = "YR1-nJ-q0v"; */
"YR1-nJ-q0v.text" = "4";

/* Class = "UILabel"; text = "每行展示照片张数"; ObjectID = "fbH-6q-oeE"; */
"fbH-6q-oeE.text" = "每行展示照片张数";

/* Class = "UILabel"; text = "把拍照/拍视频按钮放在外面"; ObjectID = "jop-5R-ioj"; */
"jop-5R-ioj.text" = "把拍照/拍视频按钮放在外面";

/* Class = "UILabel"; text = "右上角显示图片选中序号"; ObjectID = "nm2-mT-siy"; */
"nm2-mT-siy.text" = "右上角显示图片选中序号";

/* Class = "UILabel"; text = "照片最大可选张数"; ObjectID = "rK3-1U-kcW"; */
"rK3-1U-kcW.text" = "照片最大可选张数";

/* Class = "UILabel"; text = "允许选择照片"; ObjectID = "vNN-OI-9z1"; */
"vNN-OI-9z1.text" = "允许选择照片";

/* Class = "UILabel"; text = "允许选择视频"; ObjectID = "xCu-D3-IZg"; */
"xCu-D3-IZg.text" = "允许选择视频";

0 comments on commit 9434081

Please sign in to comment.