Skip to content

Commit 9434081

Browse files
author
yuzheng
committed
适配阿拉伯等语言下从右往左布局的特性
1 parent 177778f commit 9434081

8 files changed

Lines changed: 94 additions & 17 deletions

File tree

TZImagePickerController.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
9038D5901C3974F0007DE549 /* TZTestCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZTestCell.m; sourceTree = "<group>"; };
163163
903996921F447604005E77C2 /* Photos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Photos.framework; path = System/Library/Frameworks/Photos.framework; sourceTree = SDKROOT; };
164164
903996941F447609005E77C2 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; };
165+
909DBC95216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "ar-001.lproj/Main.strings"; sourceTree = "<group>"; };
166+
909DBC96216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "ar-001.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
167+
909DBC97216B981B00926570 /* ar-001 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ar-001"; path = "../ar-001.lproj/Localizable.strings"; sourceTree = "<group>"; };
165168
90A74B84203287C200D84C2A /* tz-ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "tz-ru"; path = Localizable.strings; sourceTree = "<group>"; };
166169
90CE84AC1C3A89EF003D0779 /* TZImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZImageManager.h; sourceTree = "<group>"; };
167170
90CE84AD1C3A89EF003D0779 /* TZImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZImageManager.m; sourceTree = "<group>"; };
@@ -498,6 +501,7 @@
498501
Base,
499502
"zh-Hans",
500503
"tz-ru",
504+
"ar-001",
501505
);
502506
mainGroup = 900E65731C2BB8D5003D9A9E;
503507
productRefGroup = 900E657D1C2BB8D5003D9A9E /* Products */;
@@ -643,6 +647,7 @@
643647
children = (
644648
900E65891C2BB8D5003D9A9E /* Base */,
645649
6D12FC191D66B71E00182C44 /* zh-Hans */,
650+
909DBC95216B981B00926570 /* ar-001 */,
646651
);
647652
name = Main.storyboard;
648653
sourceTree = "<group>";
@@ -652,6 +657,7 @@
652657
children = (
653658
900E658E1C2BB8D5003D9A9E /* Base */,
654659
6D12FC1A1D66B71E00182C44 /* zh-Hans */,
660+
909DBC96216B981B00926570 /* ar-001 */,
655661
);
656662
name = LaunchScreen.storyboard;
657663
sourceTree = "<group>";
@@ -660,6 +666,7 @@
660666
isa = PBXVariantGroup;
661667
children = (
662668
90A74B84203287C200D84C2A /* tz-ru */,
669+
909DBC97216B981B00926570 /* ar-001 */,
663670
);
664671
name = Localizable.strings;
665672
sourceTree = "<group>";

TZImagePickerController/TZImagePickerController/TZImagePickerController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
+ (CGFloat)tz_statusBarHeight;
310310
// 获得Info.plist数据字典
311311
+ (NSDictionary *)tz_getInfoDictionary;
312+
+ (BOOL)isRightToLeftLayout;
312313
@end
313314

314315

TZImagePickerController/TZImagePickerController/TZImagePickerController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,21 @@ + (NSDictionary *)tz_getInfoDictionary {
862862
}
863863
return infoDict ? infoDict : @{};
864864
}
865+
866+
+ (BOOL)isRightToLeftLayout {
867+
if (@available(iOS 9.0, *)) {
868+
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:UISemanticContentAttributeUnspecified] == UIUserInterfaceLayoutDirectionRightToLeft) {
869+
return YES;
870+
}
871+
} else {
872+
NSString *preferredLanguage = [NSLocale preferredLanguages].firstObject;
873+
if ([preferredLanguage hasPrefix:@"ar-"]) {
874+
return YES;
875+
}
876+
}
877+
return NO;
878+
}
879+
865880
@end
866881

867882

TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ - (void)configBottomToolBar {
211211

212212
if (tzImagePickerVc.allowPickingOriginalPhoto) {
213213
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
214-
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
214+
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, [TZCommonTools isRightToLeftLayout] ? 10 : -10, 0, 0);
215215
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
216216
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
217217
[_originalPhotoButton setTitle:tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateNormal];

TZImagePickerController/TZImagePickerController/TZPhotoPreviewController.m

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (void)viewDidLoad {
6161
[self configCustomNaviBar];
6262
[self configBottomToolBar];
6363
self.view.clipsToBounds = YES;
64-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
64+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
6565
}
6666

6767
- (void)setIsSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
@@ -78,7 +78,9 @@ - (void)viewWillAppear:(BOOL)animated {
7878
[super viewWillAppear:animated];
7979
[self.navigationController setNavigationBarHidden:YES animated:YES];
8080
[UIApplication sharedApplication].statusBarHidden = YES;
81-
if (_currentIndex) [_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * _currentIndex, 0) animated:NO];
81+
if (_currentIndex) {
82+
[_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * self.currentIndex, 0) animated:NO];
83+
}
8284
[self refreshNaviBarAndBottomBarState];
8385
}
8486

@@ -135,7 +137,7 @@ - (void)configBottomToolBar {
135137
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
136138
if (_tzImagePickerVc.allowPickingOriginalPhoto) {
137139
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
138-
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
140+
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, [TZCommonTools isRightToLeftLayout] ? 10 : -10, 0, 0);
139141
_originalPhotoButton.backgroundColor = [UIColor clearColor];
140142
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
141143
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:13];
@@ -242,7 +244,7 @@ - (void)configCropView {
242244
- (void)viewDidLayoutSubviews {
243245
[super viewDidLayoutSubviews];
244246
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
245-
247+
246248
CGFloat statusBarHeight = [TZCommonTools tz_statusBarHeight];
247249
CGFloat statusBarHeightInterval = statusBarHeight - 20;
248250
CGFloat naviBarHeight = statusBarHeight + _tzImagePickerVc.navigationBar.tz_height;
@@ -294,7 +296,7 @@ - (void)didChangeStatusBarOrientationNotification:(NSNotification *)noti {
294296

295297
- (void)select:(UIButton *)selectButton {
296298
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
297-
TZAssetModel *model = _models[_currentIndex];
299+
TZAssetModel *model = _models[self.currentIndex];
298300
if (!selectButton.isSelected) {
299301
// 1. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
300302
if (_tzImagePickerVc.selectedModels.count >= _tzImagePickerVc.maxImagesCount) {
@@ -305,8 +307,8 @@ - (void)select:(UIButton *)selectButton {
305307
} else {
306308
[_tzImagePickerVc addSelectedModel:model];
307309
if (self.photos) {
308-
[_tzImagePickerVc.selectedAssets addObject:_assetsTemp[_currentIndex]];
309-
[self.photos addObject:_photosTemp[_currentIndex]];
310+
[_tzImagePickerVc.selectedAssets addObject:_assetsTemp[self.currentIndex]];
311+
[self.photos addObject:_photosTemp[self.currentIndex]];
310312
}
311313
if (model.type == TZAssetModelMediaTypeVideo && !_tzImagePickerVc.allowPickingMultipleVideo) {
312314
[_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Select the video when in multi state, we will handle the video as a photo"]];
@@ -331,13 +333,13 @@ - (void)select:(UIButton *)selectButton {
331333
NSArray *selectedAssetsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedAssets];
332334
for (NSInteger i = 0; i < selectedAssetsTmp.count; i++) {
333335
id asset = selectedAssetsTmp[i];
334-
if ([asset isEqual:_assetsTemp[_currentIndex]]) {
336+
if ([asset isEqual:_assetsTemp[self.currentIndex]]) {
335337
[_tzImagePickerVc.selectedAssets removeObjectAtIndex:i];
336338
break;
337339
}
338340
}
339-
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[_currentIndex]];
340-
[self.photos removeObject:_photosTemp[_currentIndex]];
341+
// [_tzImagePickerVc.selectedAssets removeObject:_assetsTemp[self.currentIndex]];
342+
[self.photos removeObject:_photosTemp[self.currentIndex]];
341343
}
342344
break;
343345
}
@@ -378,10 +380,10 @@ - (void)doneButtonClick {
378380

379381
// 如果没有选中过照片 点击确定时选中当前预览的照片
380382
if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) {
381-
TZAssetModel *model = _models[_currentIndex];
383+
TZAssetModel *model = _models[self.currentIndex];
382384
[_tzImagePickerVc addSelectedModel:model];
383385
}
384-
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0];
386+
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.currentIndex inSection:0];
385387
TZPhotoPreviewCell *cell = (TZPhotoPreviewCell *)[_collectionView cellForItemAtIndexPath:indexPath];
386388
if (_tzImagePickerVc.allowCrop && [cell isKindOfClass:[TZPhotoPreviewCell class]]) { // 裁剪状态
387389
_doneButton.enabled = NO;
@@ -393,7 +395,7 @@ - (void)doneButtonClick {
393395
_doneButton.enabled = YES;
394396
[_tzImagePickerVc hideProgressHUD];
395397
if (self.doneButtonClickBlockCropMode) {
396-
TZAssetModel *model = _models[_currentIndex];
398+
TZAssetModel *model = _models[self.currentIndex];
397399
self.doneButtonClickBlockCropMode(cropedImage,model.asset);
398400
}
399401
} else if (self.doneButtonClickBlock) { // 非裁剪状态
@@ -433,7 +435,6 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
433435
offSetWidth = offSetWidth + ((self.view.tz_width + 20) * 0.5);
434436

435437
NSInteger currentIndex = offSetWidth / (self.view.tz_width + 20);
436-
437438
if (currentIndex < _models.count && _currentIndex != currentIndex) {
438439
_currentIndex = currentIndex;
439440
[self refreshNaviBarAndBottomBarState];
@@ -513,7 +514,7 @@ - (void)dealloc {
513514

514515
- (void)refreshNaviBarAndBottomBarState {
515516
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
516-
TZAssetModel *model = _models[_currentIndex];
517+
TZAssetModel *model = _models[self.currentIndex];
517518
_selectButton.selected = model.isSelected;
518519
[self refreshSelectButtonImageViewContentMode];
519520
if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex && _tzImagePickerVc.showSelectBtn) {
@@ -567,9 +568,13 @@ - (void)refreshSelectButtonImageViewContentMode {
567568
}
568569

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

576+
- (NSInteger)currentIndex {
577+
return [TZCommonTools isRightToLeftLayout] ? self.models.count - _currentIndex - 1 : _currentIndex;
578+
}
579+
575580
@end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.84 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
/* Class = "UITextField"; text = "9"; ObjectID = "37K-cO-hgf"; */
3+
"37K-cO-hgf.text" = "9";
4+
5+
/* Class = "UILabel"; text = "允许选择照片原图"; ObjectID = "7mi-Lf-2N5"; */
6+
"7mi-Lf-2N5.text" = "允许选择照片原图";
7+
8+
/* Class = "UILabel"; text = "允许多选视频/GIF/图片"; ObjectID = "7q9-aI-kbz"; */
9+
"7q9-aI-kbz.text" = "允许多选视频/GIF/图片";
10+
11+
/* Class = "UILabel"; text = "允许拍视频"; ObjectID = "8H2-cq-aUq"; */
12+
"8H2-cq-aUq.text" = "允许拍视频";
13+
14+
/* Class = "UILabel"; text = "单选模式下允许裁剪"; ObjectID = "Ibb-kN-MWC"; */
15+
"Ibb-kN-MWC.text" = "单选模式下允许裁剪";
16+
17+
/* Class = "UILabel"; text = "允许选择Gif图片"; ObjectID = "Ly2-uJ-7DN"; */
18+
"Ly2-uJ-7DN.text" = "允许选择Gif图片";
19+
20+
/* Class = "UILabel"; text = "允许拍照"; ObjectID = "R92-Zn-NWV"; */
21+
"R92-Zn-NWV.text" = "允许拍照";
22+
23+
/* Class = "UILabel"; text = "使用圆形裁剪框"; ObjectID = "TiG-df-jDs"; */
24+
"TiG-df-jDs.text" = "使用圆形裁剪框";
25+
26+
/* Class = "UILabel"; text = "照片按修改时间升序排列"; ObjectID = "UL3-n3-Hmt"; */
27+
"UL3-n3-Hmt.text" = "照片按修改时间升序排列";
28+
29+
/* Class = "UITextField"; text = "4"; ObjectID = "YR1-nJ-q0v"; */
30+
"YR1-nJ-q0v.text" = "4";
31+
32+
/* Class = "UILabel"; text = "每行展示照片张数"; ObjectID = "fbH-6q-oeE"; */
33+
"fbH-6q-oeE.text" = "每行展示照片张数";
34+
35+
/* Class = "UILabel"; text = "把拍照/拍视频按钮放在外面"; ObjectID = "jop-5R-ioj"; */
36+
"jop-5R-ioj.text" = "把拍照/拍视频按钮放在外面";
37+
38+
/* Class = "UILabel"; text = "右上角显示图片选中序号"; ObjectID = "nm2-mT-siy"; */
39+
"nm2-mT-siy.text" = "右上角显示图片选中序号";
40+
41+
/* Class = "UILabel"; text = "照片最大可选张数"; ObjectID = "rK3-1U-kcW"; */
42+
"rK3-1U-kcW.text" = "照片最大可选张数";
43+
44+
/* Class = "UILabel"; text = "允许选择照片"; ObjectID = "vNN-OI-9z1"; */
45+
"vNN-OI-9z1.text" = "允许选择照片";
46+
47+
/* Class = "UILabel"; text = "允许选择视频"; ObjectID = "xCu-D3-IZg"; */
48+
"xCu-D3-IZg.text" = "允许选择视频";

0 commit comments

Comments
 (0)