From ee20320932b9830bf95e1b6076df6979cfe05894 Mon Sep 17 00:00:00 2001 From: gaoyu Date: Thu, 14 Sep 2017 18:14:44 +0800 Subject: [PATCH] complete localizable.strings --- LPAlbum.xcodeproj/project.pbxproj | 12 ++- .../Controllers/AlbumDetailController.swift | 19 ---- LPAlbum/Controllers/LPAlbum.swift | 33 ++++-- .../Controllers/PhotosPreviewController.swift | 96 ++++++++++++++++++ LPAlbum/Others/AlbumError.swift | 8 +- LPAlbum/Others/Extensions.swift | 15 +++ .../en.lproj/Localizable.strings | Bin 0 -> 432 bytes .../zh.lproj/Localizable.strings | Bin 0 -> 288 bytes LPAlbum/Views/PhotoPreviewCell.swift | 71 +++++++++++++ 9 files changed, 221 insertions(+), 33 deletions(-) delete mode 100644 LPAlbum/Controllers/AlbumDetailController.swift create mode 100644 LPAlbum/Controllers/PhotosPreviewController.swift create mode 100644 LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings create mode 100644 LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings create mode 100644 LPAlbum/Views/PhotoPreviewCell.swift diff --git a/LPAlbum.xcodeproj/project.pbxproj b/LPAlbum.xcodeproj/project.pbxproj index 08b1ad6..92aaab3 100644 --- a/LPAlbum.xcodeproj/project.pbxproj +++ b/LPAlbum.xcodeproj/project.pbxproj @@ -17,7 +17,7 @@ 731A48291F623B3E00AC5513 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 731A48271F623B3E00AC5513 /* LaunchScreen.storyboard */; }; 7337B6741F6850C800F1FE84 /* PhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7337B6731F6850C800F1FE84 /* PhotoCell.swift */; }; 737FCD111F6241CC00C44C3D /* AlbumViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737FCD101F6241CC00C44C3D /* AlbumViewController.swift */; }; - 738C26041F67934D00040E4E /* AlbumDetailController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26031F67934D00040E4E /* AlbumDetailController.swift */; }; + 738C26041F67934D00040E4E /* PhotosPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26031F67934D00040E4E /* PhotosPreviewController.swift */; }; 738C26061F67C94500040E4E /* TakeCameraCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C26051F67C94500040E4E /* TakeCameraCell.swift */; }; 738C260B1F67E43200040E4E /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 738C260A1F67E43200040E4E /* Extensions.swift */; }; 739180FB1F6677BE001EACFF /* LPAlbum.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 731A47FE1F623AF000AC5513 /* LPAlbum.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -32,6 +32,7 @@ 7391811D1F66A33C001EACFF /* DropMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7391811B1F66A33C001EACFF /* DropMenuView.swift */; }; 7391811F1F66B3A4001EACFF /* TitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7391811C1F66A33C001EACFF /* TitleView.swift */; }; 73A85A881F68EDF000C3096E /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73A85A871F68EDF000C3096E /* Config.swift */; }; + 73BF7BF01F6A24E400A0BEC1 /* PhotoPreviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -73,7 +74,7 @@ 731A482A1F623B3E00AC5513 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7337B6731F6850C800F1FE84 /* PhotoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCell.swift; sourceTree = ""; }; 737FCD101F6241CC00C44C3D /* AlbumViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlbumViewController.swift; sourceTree = ""; }; - 738C26031F67934D00040E4E /* AlbumDetailController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlbumDetailController.swift; sourceTree = ""; }; + 738C26031F67934D00040E4E /* PhotosPreviewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosPreviewController.swift; sourceTree = ""; }; 738C26051F67C94500040E4E /* TakeCameraCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TakeCameraCell.swift; sourceTree = ""; }; 738C260A1F67E43200040E4E /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 739181071F669FC9001EACFF /* LPAlbum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LPAlbum.swift; sourceTree = ""; }; @@ -87,6 +88,7 @@ 7391811B1F66A33C001EACFF /* DropMenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropMenuView.swift; sourceTree = ""; }; 7391811C1F66A33C001EACFF /* TitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleView.swift; sourceTree = ""; }; 73A85A871F68EDF000C3096E /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; + 73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoPreviewCell.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -176,7 +178,7 @@ children = ( 739181071F669FC9001EACFF /* LPAlbum.swift */, 739181081F669FC9001EACFF /* LPNavigationController.swift */, - 738C26031F67934D00040E4E /* AlbumDetailController.swift */, + 738C26031F67934D00040E4E /* PhotosPreviewController.swift */, ); path = Controllers; sourceTree = ""; @@ -202,6 +204,7 @@ 7391811C1F66A33C001EACFF /* TitleView.swift */, 739181191F669FD2001EACFF /* AlbumCollectionCell.swift */, 738C26051F67C94500040E4E /* TakeCameraCell.swift */, + 73BF7BEF1F6A24E400A0BEC1 /* PhotoPreviewCell.swift */, ); path = Views; sourceTree = ""; @@ -357,9 +360,10 @@ files = ( 739181091F669FC9001EACFF /* LPAlbum.swift in Sources */, 7391811D1F66A33C001EACFF /* DropMenuView.swift in Sources */, - 738C26041F67934D00040E4E /* AlbumDetailController.swift in Sources */, + 738C26041F67934D00040E4E /* PhotosPreviewController.swift in Sources */, 7391811A1F669FD2001EACFF /* AlbumCollectionCell.swift in Sources */, 738C26061F67C94500040E4E /* TakeCameraCell.swift in Sources */, + 73BF7BF01F6A24E400A0BEC1 /* PhotoPreviewCell.swift in Sources */, 739181131F669FCE001EACFF /* AlbumManager.swift in Sources */, 73A85A881F68EDF000C3096E /* Config.swift in Sources */, 739181141F669FCE001EACFF /* AuthorizationTool.swift in Sources */, diff --git a/LPAlbum/Controllers/AlbumDetailController.swift b/LPAlbum/Controllers/AlbumDetailController.swift deleted file mode 100644 index ccfaa60..0000000 --- a/LPAlbum/Controllers/AlbumDetailController.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// AlbumDetailController.swift -// LPAlbum -// -// Created by 郜宇 on 2017/9/12. -// Copyright © 2017年 Loopeer. All rights reserved. -// - -import UIKit - - -// TODO: 相册详情视图 -class AlbumDetailController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - - } -} diff --git a/LPAlbum/Controllers/LPAlbum.swift b/LPAlbum/Controllers/LPAlbum.swift index 07ce64a..1728457 100644 --- a/LPAlbum/Controllers/LPAlbum.swift +++ b/LPAlbum/Controllers/LPAlbum.swift @@ -4,7 +4,20 @@ // // Created by 郜宇 on 2017/9/8. // Copyright © 2017年 Loopeer. All rights reserved. -// TODO: 1. add CompleteSelectAssetsBlock +/** + TODO: 1. add CompleteSelectAssetsBlock + 2. add Photo Cache + 3. 文本国际化 + 4. 图片详情展示 + 5. 选取单个图片的情形 + 6. 支持裁剪(正方形, 圆形) + 7. take photo statusBarAnimation + 8. 是否要加Observer + 9. 完善demo(照片墙, 权限跳转) + 10. 加一些动画效果 + 11. 添加注释 + 12. 是否内部对图片处理画一遍 + */ import UIKit import Photos @@ -21,9 +34,6 @@ public class LPAlbum: UIViewController { fileprivate var errorBlock: ErrorBlock? fileprivate var targetSizeBlock: TargetSizeBlock? - fileprivate var cameraStatus: AVAuthorizationStatus! - fileprivate var albumStatus: PHAuthorizationStatus! - fileprivate var albumManager: AlbumManager! fileprivate var collectionView: UICollectionView! fileprivate var titleView: TitleView! @@ -117,8 +127,8 @@ public class LPAlbum: UIViewController { extension LPAlbum { func setupUI() { - navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: .plain, target: self, action: #selector(cancel)) - navigationItem.rightBarButtonItem = UIBarButtonItem(title: "完成", style: .plain, target: self, action: #selector(confirm)) + navigationItem.leftBarButtonItem = UIBarButtonItem(title: String.local("取消"), style: .plain, target: self, action: #selector(cancel)) + navigationItem.rightBarButtonItem = UIBarButtonItem(title: String.local("完成"), style: .plain, target: self, action: #selector(confirm)) titleView = TitleView(frame: .zero) navigationItem.titleView = titleView @@ -197,6 +207,17 @@ extension LPAlbum: UICollectionViewDelegate, UICollectionViewDataSource { AuthorizationTool.cameraRequestAuthorization{ $0 == .authorized ? self.takePhoto() : self.errorBlock?(self, AlbumError.noCameraPermission) } + }else{ + let previewVc = PhotosPreviewController() + previewVc.assetModels = albumModels[currentAlbumIndex].assetModels + previewVc.currentIndex = config.hasCamera ? indexPath.row - 1 : indexPath.row + previewVc.chooseAction = {[weak self] in + guard let `self` = self else { return } + self.albumModels = self.albumModels.change(assetModel: $0) + let currentIndex = self.config.hasCamera ? $1 + 1 : $1 + self.collectionView.reloadItems(at: [IndexPath(row: currentIndex, section: 0)]) + } + navigationController?.pushViewController(previewVc, animated: true) } } diff --git a/LPAlbum/Controllers/PhotosPreviewController.swift b/LPAlbum/Controllers/PhotosPreviewController.swift new file mode 100644 index 0000000..0e0d49e --- /dev/null +++ b/LPAlbum/Controllers/PhotosPreviewController.swift @@ -0,0 +1,96 @@ +// +// AlbumDetailController.swift +// LPAlbum +// +// Created by 郜宇 on 2017/9/12. +// Copyright © 2017年 Loopeer. All rights reserved. +// + +import UIKit + +class PhotosPreviewController: UIViewController { + + var assetModels: [AssetModel]! + var currentIndex: Int! + + var chooseAction: ((AssetModel, Int) -> Void)? + + fileprivate var collectionView: UICollectionView! + fileprivate let itemPadding: CGFloat = 20.0 + fileprivate let chooseButton = UIButton() + + override func viewDidLoad() { + super.viewDidLoad() + setupUI() + } +} + +extension PhotosPreviewController { + + func setupUI(){ + // 将collectionView多余的部分切到 + view.clipsToBounds = true + + chooseButton.frame = CGRect(x: 0, y: 0, width: 25, height: 25) + chooseButton.setBackgroundImage(LPAlbum.Style.selectedBox, for: .selected) + chooseButton.setBackgroundImage(LPAlbum.Style.normalBox, for: .normal) + chooseButton.isSelected = assetModels[currentIndex].isSelect + chooseButton.addTarget(self, action: #selector(chooseClick), for: .touchUpInside) + navigationItem.rightBarButtonItem = UIBarButtonItem(customView: chooseButton) + + let layout = UICollectionViewFlowLayout() + let itemSize = CGSize(width: view.bounds.width + 20, height: view.bounds.height - 64) + layout.itemSize = itemSize + layout.minimumLineSpacing = 0 + layout.minimumInteritemSpacing = 0 + layout.scrollDirection = .horizontal + collectionView = UICollectionView(frame: CGRect(x: -10, y: 0, width: itemSize.width, height: itemSize.height), + collectionViewLayout: layout) + collectionView.isPagingEnabled = true + collectionView.showsHorizontalScrollIndicator = false + collectionView.delegate = self + collectionView.dataSource = self + view.addSubview(collectionView) + collectionView.register(PhotoPreviewCell.self, forCellWithReuseIdentifier: PhotoPreviewCell.description()) + collectionView.performBatchUpdates(nil){ _ in + self.collectionView.setContentOffset(CGPoint(x: itemSize.width * self.currentIndex.cgFloat, y: 0), animated: false) + } + } + func chooseClick() { + chooseButton.isSelected = !chooseButton.isSelected + assetModels[currentIndex].isSelect = chooseButton.isSelected + + var model = assetModels[currentIndex] + model.isSelect = chooseButton.isSelected + chooseAction?(model, currentIndex) + } +} + +extension PhotosPreviewController: UICollectionViewDelegate, UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return assetModels.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoPreviewCell.description(), for: indexPath) as! PhotoPreviewCell + cell.assetModel = assetModels[indexPath.row] + return cell + } + func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + (cell as? PhotoPreviewCell)?.resetZoomScale() + } + + func scrollViewDidScroll(_ scrollView: UIScrollView) { + currentIndex = (scrollView.contentOffset.x / scrollView.bounds.width).roundInt + chooseButton.isSelected = assetModels[currentIndex].isSelect + } +} + + + + + + + + + diff --git a/LPAlbum/Others/AlbumError.swift b/LPAlbum/Others/AlbumError.swift index e4321f3..e042ac5 100644 --- a/LPAlbum/Others/AlbumError.swift +++ b/LPAlbum/Others/AlbumError.swift @@ -16,10 +16,10 @@ public enum AlbumError: Error { public var localizedDescription: String { switch self { - case .noAlbumPermission: return "没有相册访问权限" - case .noCameraPermission: return "没有相机访问权限" - case .moreThanLargestChoiceCount: return "超出了可选择图片数量的上限" - case .savePhotoError: return "保存图片失败" + case .noAlbumPermission: return String.local("没有相册访问权限") + case .noCameraPermission: return String.local("没有摄像头访问权限") + case .moreThanLargestChoiceCount: return String.local("达到了图片选择最大数量") + case .savePhotoError: return String.local("保存图片失败") } } } diff --git a/LPAlbum/Others/Extensions.swift b/LPAlbum/Others/Extensions.swift index 477184c..6e2444d 100644 --- a/LPAlbum/Others/Extensions.swift +++ b/LPAlbum/Others/Extensions.swift @@ -11,6 +11,8 @@ import Foundation extension CGFloat { static var screenWidth = UIScreen.main.bounds.width static var screenHeight = UIScreen.main.bounds.height + + var roundInt: Int { return Int(self.rounded()) } } extension Int { @@ -37,6 +39,15 @@ extension Bundle { let path = bundle.path(forResource: imageName, ofType: "png") else { return nil } return UIImage(contentsOfFile: path) } + + static func localizedString(key: String) -> String { + guard let code = Locale.current.languageCode else { return key } + var language = "zh" + if code == "en" { language = "en" } + guard let path = albumBundle.path(forResource: language, ofType: "lproj"), + let bundle = Bundle(path: path) else { return key } + return bundle.localizedString(forKey: key, value: nil, table: nil) + } } @@ -145,6 +156,10 @@ extension String { var isAvailableAlbum: Bool { return !(isEmpty || contains("Hidden") || contains("已隐藏") || contains("Deleted") || contains("最近删除")) } + + static func local(_ key: String) -> String { + return Bundle.localizedString(key: key) + } } diff --git a/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings b/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings new file mode 100644 index 0000000000000000000000000000000000000000..dc67ed08d3f411b840d1eff43a2c9c685f0df616 GIT binary patch literal 432 zcmezWPl@4La7V5Zg93vs5Gye_GbA$PF(fmjGUNbx)(l)gvL{*~38BJ;As?tB6)wB4 z-yo>X?_ZdE5$A-LNet=gkp-#eCnD5COjH2s$!915+L6qV0c7Pf6a&prV8{isiomP_ zhD@Mb2}3EEUko?@O8>nuglSGd_a!rA!(|udaHjt#>j~W7{cfsrdcZV)X7`50uXOUn5GlSo|VCIj7(3v_o8kOtX; v&$PS#5z(OVF^p90MYt~*sIv_0^AeyNL1BR!0tyUiKoyxlH>WbBKwSm^ZrxhP literal 0 HcmV?d00001 diff --git a/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings b/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings new file mode 100644 index 0000000000000000000000000000000000000000..1719bb7a59e28c9bc59bf8f4c56c81c24208b0e4 GIT binary patch literal 288 zcmezWPl@4La7V5Zg93vs5W{%Z3|v5VPqaW1LI%Qv$n5Jk2x{~D7v^5XIpJjzL%Moo zLF)O52(`H6A-b>h-wQ*ih43IU3v)Qrf0XqE?(cp#)j2(28bTGO3_^!X%J~43NbGvh Y UIView? { + return photoView + } + + func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) { + scrollView.contentInset = .zero + } + + func scrollViewDidZoom(_ scrollView: UIScrollView) { +// let scrollViewW = scrollView.frame.width +// let scrollViewH = scrollView.frame.height +// let contentSizeW = scrollView.contentSize.width +// let contentSizeH = scrollView.contentSize.height +// +// let offsetX = scrollViewW > contentSizeW ? scrollViewW - contentSizeW * 0.5 : 0 +// let offsetY = scrollViewH > contentSizeH ? scrollViewH - contentSizeH * 0.5 : 0 +// photoView.center = CGPoint(x: contentSizeW * 0.5 + offsetX, y: contentSizeH * 0.5 + offsetY) + } + +} + +