Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
57b50331
authored
Jan 08, 2020
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正图片选择逻辑,添加提示语
parent
3f373fd4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
42 deletions
+89
-42
MRFramework/MRFramework/UIControls/Album/Interface/MRAlbumCell.swift
+1
-1
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
+10
-1
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
+77
-39
MRFramework/MRFramework/UIControls/PhotoPicker/SAPhotoPicker.swift
+1
-1
No files found.
MRFramework/MRFramework/UIControls/Album/Interface/MRAlbumCell.swift
View file @
57b50331
...
...
@@ -15,7 +15,7 @@ public final class MRAlbumCell: UICollectionViewCell {
/// 默认的勾选按钮大小
public
static
var
checkboxSize
:
CGSize
=
CGSize
(
width
:
30
,
height
:
30
)
/// 默认的勾选按钮非选择状态配置
public
static
var
deselectedCheckboxOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
clear
)
public
static
var
deselectedCheckboxOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
init
(
0x333333
,
alpha
:
0.5
)
)
/// 默认的勾选按钮选择状态配置
public
static
var
selectedCheckboxOptions
:
MRCheckBoxOptions
=
.
defaultCheck
(
checkboxSize
)
...
...
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
View file @
57b50331
...
...
@@ -27,7 +27,7 @@ open class MRAlbumDetailViewController: UIViewController {
/// 默认勾选按钮大小
public
static
var
checkboxSize
=
CGSize
(
width
:
40
,
height
:
40
)
/// 默认勾选按钮非选择状态的显示配置
public
static
var
unCheckOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
clear
)
public
static
var
unCheckOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
init
(
0x333333
,
alpha
:
0.5
)
)
/// 默认勾选按钮选择状态的显示配置
public
static
var
checkedOptions
:
MRCheckBoxOptions
=
.
defaultCheck
(
checkboxSize
)
...
...
@@ -40,6 +40,10 @@ open class MRAlbumDetailViewController: UIViewController {
public
var
assest
:
PHAsset
!
/// 是否选择了图片
public
var
isSelected
=
false
public
var
maxSelectCount
=
0
public
var
currentSelectedCount
=
0
/// 图片缓存
public
var
imageCache
=
PHCachingImageManager
()
...
...
@@ -111,6 +115,11 @@ extension MRAlbumDetailViewController {
}
@objc
private
func
checkboxDidPress
(
_
sender
:
UIButton
)
{
if
isSelected
==
false
,
currentSelectedCount
==
maxSelectCount
{
"您只能选择
\(
maxSelectCount
)
个图片文件"
.
toast
()
return
}
sender
.
isSelected
=
!
sender
.
isSelected
isSelected
=
sender
.
isSelected
}
...
...
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
View file @
57b50331
...
...
@@ -150,27 +150,34 @@ 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
)
{
selectedAssests
.
removeAll
(
where
:
{
$0
==
selected
})
cell
.
isSelected
=
false
return
}
if
selectedAssests
.
count
>=
maxCount
{
return
}
selectedAssests
.
append
(
selected
)
if
!
collectionView
.
allowsMultipleSelection
{
confirm
()
}
else
{
cell
.
isSelected
=
true
if
let
selected
=
assests
?
.
object
(
at
:
indexPath
.
row
)
{
set
(
asset
:
selected
,
selected
:
true
,
completion
:
{
isSelected
in
cell
.
isSelected
=
isSelected
if
isSelected
==
true
,
self
.
maxCount
==
1
{
self
.
confirm
()
}
}
}
)
}
// if maxCount > 0, let selected = assests?.object(at: indexPath.row) {
// if selectedAssests.contains(selected) {
// selectedAssests.removeAll(where: { $0 == selected })
// cell.isSelected = false
// return
// }
//
// if selectedAssests.count >= maxCount {
// return
// }
//
// selectedAssests.append(selected)
// if !collectionView.allowsMultipleSelection {
// confirm()
// } else {
// cell.isSelected = true
// }
// }
}
/// 添加返回按钮。该按钮只在相册属于nav的首个vc的时候创建,可以自定义。
...
...
@@ -220,29 +227,38 @@ open class MRAlbumListViewController: UIViewController {
let
vc
=
MRAlbumDetailViewController
()
vc
.
assest
=
assest
vc
.
isSelected
=
selectedAssests
.
contains
(
assest
)
vc
.
maxSelectCount
=
maxCount
vc
.
currentSelectedCount
=
selectedAssests
.
count
vc
.
imageCache
=
imageCache
vc
.
confirm
=
{
vc
,
isSelected
in
var
removedIndex
=
NSNotFound
if
isSelected
,
!
self
.
selectedAssests
.
contains
(
assest
)
{
if
self
.
selectedAssests
.
count
==
self
.
maxCount
{
if
let
assests
=
self
.
assests
,
let
removeItem
=
self
.
selectedAssests
.
first
{
removedIndex
=
assests
.
index
(
of
:
removeItem
)
}
if
removedIndex
!=
NSNotFound
,
let
cell
=
collectionView
.
cellForItem
(
at
:
IndexPath
(
row
:
removedIndex
,
section
:
0
))
{
cell
.
isSelected
=
false
}
self
.
selectedAssests
.
remove
(
at
:
0
)
self
.
set
(
asset
:
assest
,
selected
:
isSelected
,
completion
:
{
selected
in
if
let
cell
=
collectionView
.
cellForItem
(
at
:
indexPath
)
{
cell
.
isSelected
=
isSelected
}
self
.
selectedAssests
.
append
(
assest
)
}
else
if
!
isSelected
{
self
.
selectedAssests
.
removeAll
(
where
:
{
$0
==
assest
})
}
if
let
cell
=
collectionView
.
cellForItem
(
at
:
indexPath
)
{
cell
.
isSelected
=
isSelected
}
})
// var removedIndex = NSNotFound
// if isSelected, !self.selectedAssests.contains(assest) {
// if self.selectedAssests.count == self.maxCount {
// if let assests = self.assests,
// let removeItem = self.selectedAssests.first {
// removedIndex = assests.index(of: removeItem)
// }
// if removedIndex != NSNotFound,
// let cell = collectionView.cellForItem(at: IndexPath(row: removedIndex, section: 0)) {
// cell.isSelected = false
// }
//
// self.selectedAssests.remove(at: 0)
// }
// self.selectedAssests.append(assest)
// } else if !isSelected {
// self.selectedAssests.removeAll(where: { $0 == assest })
// }
// if let cell = collectionView.cellForItem(at: indexPath) {
// cell.isSelected = isSelected
// }
}
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
...
...
@@ -413,6 +429,28 @@ extension MRAlbumListViewController {
break
}
}
private
func
set
(
asset
:
PHAsset
,
selected
:
Bool
,
completion
:
((
_
selected
:
Bool
)
->
Void
)?
=
nil
)
{
guard
maxCount
>
0
else
{
completion
?(
false
)
return
}
if
selected
==
false
||
(
selectedAssests
.
contains
(
asset
)
&&
selected
==
true
)
{
selectedAssests
.
removeAll
(
where
:
{
$0
==
asset
})
completion
?(
false
)
return
}
if
selectedAssests
.
count
>=
maxCount
{
"您只能选择
\(
maxCount
)
个图片文件"
.
toast
()
completion
?(
false
)
return
}
selectedAssests
.
append
(
asset
)
completion
?(
true
)
}
}
extension
MRAlbumListViewController
{
...
...
MRFramework/MRFramework/UIControls/PhotoPicker/SAPhotoPicker.swift
View file @
57b50331
...
...
@@ -127,7 +127,6 @@ extension SAPhotoPicker {
vc
.
title
=
config
[
.
albumTitle
]
as?
String
vc
.
maxCount
=
count
vc
.
maxImageSize
=
imageMaxSize
vc
.
modalPresentationStyle
=
.
fullScreen
vc
.
didConfirm
=
{
vc
,
images
,
count
in
self
.
complateBlock
?(
vc
,
images
,
nil
,
count
,
nil
)
}
...
...
@@ -136,6 +135,7 @@ extension SAPhotoPicker {
}
customAlbumSetting
?(
self
,
vc
)
let
nav
=
UINavigationController
(
rootViewController
:
vc
)
nav
.
modalPresentationStyle
=
.
fullScreen
if
let
from
=
viewController
{
from
.
present
(
nav
,
animated
:
true
)
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment