diff --git a/LPAlbum/Controllers/LPAlbum.swift b/LPAlbum/Controllers/LPAlbum.swift index 1728457..48c20a2 100644 --- a/LPAlbum/Controllers/LPAlbum.swift +++ b/LPAlbum/Controllers/LPAlbum.swift @@ -186,7 +186,7 @@ extension LPAlbum: UICollectionViewDelegate, UICollectionViewDataSource { cell.set(model) cell.iconClickAction = {[weak self] in guard let `self` = self else { return } - guard self.checkoutMaxCount(willselect: !$0) else { return } + guard self.checkoutMaxCount(willselect: !$0, show: self) else { return } var newModel = model newModel.isSelect = !$0 self.albumModels = self.albumModels.change(assetModel: newModel) @@ -203,19 +203,27 @@ extension LPAlbum: UICollectionViewDelegate, UICollectionViewDataSource { public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { if config.hasCamera && indexPath.row == 0 { - guard checkoutMaxCount(willselect: true) else { return } + guard checkoutMaxCount(willselect: true, show: self) else { return } AuthorizationTool.cameraRequestAuthorization{ $0 == .authorized ? self.takePhoto() : self.errorBlock?(self, AlbumError.noCameraPermission) } }else{ let previewVc = PhotosPreviewController() - previewVc.assetModels = albumModels[currentAlbumIndex].assetModels + let assetModels = albumModels[currentAlbumIndex].assetModels + previewVc.assetModels = assetModels previewVc.currentIndex = config.hasCamera ? indexPath.row - 1 : indexPath.row - previewVc.chooseAction = {[weak self] in + previewVc.chooseAction = {[weak self] (index, button, vc) 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)]) + + let willselect = !button.isSelected + guard self.checkoutMaxCount(willselect: willselect, show: vc) else { return } + + button.isSelected = willselect + vc.assetModels[index].isSelect = willselect + self.albumModels = self.albumModels.change(assetModel: vc.assetModels[index]) + + let cellIndex = self.config.hasCamera ? index + 1 : index + self.collectionView.reloadItems(at: [IndexPath(row: cellIndex, section: 0)]) } navigationController?.pushViewController(previewVc, animated: true) } @@ -231,9 +239,9 @@ extension LPAlbum: UICollectionViewDelegate, UICollectionViewDataSource { present(picker, animated: true, completion: nil) } - func checkoutMaxCount(willselect: Bool) -> Bool { + func checkoutMaxCount(willselect: Bool, show vc: UIViewController) -> Bool { if self.config.maxSelectCount == self.albumModels[0].selectCount && willselect { - self.errorBlock?(self,AlbumError.moreThanLargestChoiceCount) + self.errorBlock?(vc,AlbumError.moreThanLargestChoiceCount) return false } return true diff --git a/LPAlbum/Controllers/PhotosPreviewController.swift b/LPAlbum/Controllers/PhotosPreviewController.swift index 0e0d49e..36f9062 100644 --- a/LPAlbum/Controllers/PhotosPreviewController.swift +++ b/LPAlbum/Controllers/PhotosPreviewController.swift @@ -13,7 +13,7 @@ class PhotosPreviewController: UIViewController { var assetModels: [AssetModel]! var currentIndex: Int! - var chooseAction: ((AssetModel, Int) -> Void)? + var chooseAction: ((Int, UIButton, PhotosPreviewController) -> Void)? fileprivate var collectionView: UICollectionView! fileprivate let itemPadding: CGFloat = 20.0 @@ -23,6 +23,9 @@ class PhotosPreviewController: UIViewController { super.viewDidLoad() setupUI() } + deinit { + print("\(self) deinit") + } } extension PhotosPreviewController { @@ -57,12 +60,7 @@ extension PhotosPreviewController { } } func chooseClick() { - chooseButton.isSelected = !chooseButton.isSelected - assetModels[currentIndex].isSelect = chooseButton.isSelected - - var model = assetModels[currentIndex] - model.isSelect = chooseButton.isSelected - chooseAction?(model, currentIndex) + chooseAction?(currentIndex, chooseButton, self) } } diff --git a/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings b/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings index dc67ed0..749862b 100644 Binary files a/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings and b/LPAlbum/Others/LPAlbum.bundle/en.lproj/Localizable.strings differ diff --git a/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings b/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings index 1719bb7..9a3bc6e 100644 Binary files a/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings and b/LPAlbum/Others/LPAlbum.bundle/zh.lproj/Localizable.strings differ