Commit 73a54df2 by Sarkizz

修正自定义多选相册的逻辑

parent c013ba33
...@@ -71,12 +71,15 @@ open class MRAlbumDetailViewController: UIViewController { ...@@ -71,12 +71,15 @@ open class MRAlbumDetailViewController: UIViewController {
open override func viewWillAppear(_ animated: Bool) { open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false) // navigationController?.setNavigationBarHidden(true, animated: false)
} }
open override func viewWillDisappear(_ animated: Bool) { open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: false) // navigationController?.setNavigationBarHidden(false, animated: false)
if state == .loading {
state = .none
}
} }
open override var prefersStatusBarHidden: Bool { open override var prefersStatusBarHidden: Bool {
...@@ -175,8 +178,8 @@ extension MRAlbumDetailViewController { ...@@ -175,8 +178,8 @@ extension MRAlbumDetailViewController {
setupMainViews() setupMainViews()
setupLayouts() setupLayouts()
resizeImageView() resizeImageView()
default: case .none:
break self.imageCache.stopCachingImagesForAllAssets()
} }
} }
......
...@@ -150,6 +150,7 @@ open class MRAlbumListViewController: UIViewController { ...@@ -150,6 +150,7 @@ open class MRAlbumListViewController: UIViewController {
/// - Parameter cell: cell /// - Parameter cell: cell
/// - Parameter indexPath: indexPath /// - Parameter indexPath: indexPath
open func didClickOnCellCheck(_ cell: UICollectionViewCell, at indexPath: IndexPath) { open func didClickOnCellCheck(_ cell: UICollectionViewCell, at indexPath: IndexPath) {
if maxCount > 0 {
if let selected = assests?.object(at: indexPath.row) { if let selected = assests?.object(at: indexPath.row) {
if selectedAssests.contains(selected) { if selectedAssests.contains(selected) {
...@@ -170,6 +171,7 @@ open class MRAlbumListViewController: UIViewController { ...@@ -170,6 +171,7 @@ open class MRAlbumListViewController: UIViewController {
} }
} }
} }
}
/// 添加返回按钮。该按钮只在相册属于nav的首个vc的时候创建,可以自定义。 /// 添加返回按钮。该按钮只在相册属于nav的首个vc的时候创建,可以自定义。
open func addNavButtonIfNeeded() { open func addNavButtonIfNeeded() {
...@@ -183,7 +185,6 @@ open class MRAlbumListViewController: UIViewController { ...@@ -183,7 +185,6 @@ open class MRAlbumListViewController: UIViewController {
let backItem = UIBarButtonItem(customView: button) let backItem = UIBarButtonItem(customView: button)
navigationItem.leftBarButtonItem = backItem navigationItem.leftBarButtonItem = backItem
if collectionView.allowsMultipleSelection {
let confirmBtn = UIButton(type: .custom) let confirmBtn = UIButton(type: .custom)
confirmBtn.frame = CGRect(x: 0, y: 0, width: 50, height: 40) confirmBtn.frame = CGRect(x: 0, y: 0, width: 50, height: 40)
confirmBtn.setTitle("确定", for: .normal) confirmBtn.setTitle("确定", for: .normal)
...@@ -193,7 +194,6 @@ open class MRAlbumListViewController: UIViewController { ...@@ -193,7 +194,6 @@ open class MRAlbumListViewController: UIViewController {
navigationItem.rightBarButtonItem = item navigationItem.rightBarButtonItem = item
} }
} }
}
/// 最大选择数量变化后的回调 /// 最大选择数量变化后的回调
open func maxCountDidChange() { open func maxCountDidChange() {
...@@ -205,7 +205,7 @@ open class MRAlbumListViewController: UIViewController { ...@@ -205,7 +205,7 @@ open class MRAlbumListViewController: UIViewController {
collectionView.allowsMultipleSelection = maxCount > 1 collectionView.allowsMultipleSelection = maxCount > 1
let count = selectedAssests.count - maxCount let count = selectedAssests.count - maxCount
if count > 0 { if count > 0 {
selectedAssests.removeLast(count) selectedAssests.removeFirst(count)
} }
} }
collectionView.reloadData() collectionView.reloadData()
...@@ -222,8 +222,22 @@ open class MRAlbumListViewController: UIViewController { ...@@ -222,8 +222,22 @@ open class MRAlbumListViewController: UIViewController {
vc.isSelected = selectedAssests.contains(assest) vc.isSelected = selectedAssests.contains(assest)
vc.imageCache = imageCache vc.imageCache = imageCache
vc.confirm = { vc, isSelected in vc.confirm = { vc, isSelected in
var removedIndex = NSNotFound
if isSelected, !self.selectedAssests.contains(assest) { if isSelected, !self.selectedAssests.contains(assest) {
if self.selectedAssests.count == self.maxCount {
let removedAssest = self.selectedAssests[0]
if let assests = self.assests {
removedIndex = assests.index(of: assest)
}
if removedIndex != NSNotFound,
let cell = collectionView.cellForItem(at: IndexPath(row: removedIndex, section: 0)) {
cell.isSelected = false
}
self.selectedAssests[0] = assest
} else {
self.selectedAssests.append(assest) self.selectedAssests.append(assest)
}
} else if !isSelected { } else if !isSelected {
self.selectedAssests.removeAll(where: { $0 == assest }) self.selectedAssests.removeAll(where: { $0 == assest })
} }
...@@ -242,11 +256,15 @@ open class MRAlbumListViewController: UIViewController { ...@@ -242,11 +256,15 @@ open class MRAlbumListViewController: UIViewController {
/// 点击确定 /// 点击确定
@objc open func confirm() { @objc open func confirm() {
if selectedAssests.count > 0 {
ToastView.loading() ToastView.loading()
requestImages(with: selectedAssests, size: maxImageSize) { (images, count) in requestImages(with: selectedAssests, size: maxImageSize) { (images, count) in
ToastView.hide(animate: false) ToastView.hide(animate: false)
self.didConfirm?(self, images, count) self.didConfirm?(self, images, count)
} }
} else {
self.didCancel?(self)
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment