Commit 73a54df2 by Sarkizz

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

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