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
73a54df2
authored
Oct 31, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正自定义多选相册的逻辑
parent
c013ba33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
36 deletions
+57
-36
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
+7
-4
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
+50
-32
No files found.
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
View file @
73a54df2
...
...
@@ -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
()
}
}
...
...
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
View file @
73a54df2
...
...
@@ -150,23 +150,25 @@ open class MRAlbumListViewController: UIViewController {
/// - Parameter cell: cell
/// - Parameter indexPath: indexPath
open
func
didClickOnCellCheck
(
_
cell
:
UICollectionViewCell
,
at
indexPath
:
IndexPath
)
{
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
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
}
}
}
}
...
...
@@ -183,15 +185,13 @@ 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
)
confirmBtn
.
setTitleColor
(
.
init
(
0x333333
),
for
:
.
normal
)
confirmBtn
.
addTarget
(
self
,
action
:
#selector(
confirm
)
,
for
:
.
touchUpInside
)
let
item
=
UIBarButtonItem
(
customView
:
confirmBtn
)
navigationItem
.
rightBarButtonItem
=
item
}
let
confirmBtn
=
UIButton
(
type
:
.
custom
)
confirmBtn
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
50
,
height
:
40
)
confirmBtn
.
setTitle
(
"确定"
,
for
:
.
normal
)
confirmBtn
.
setTitleColor
(
.
init
(
0x333333
),
for
:
.
normal
)
confirmBtn
.
addTarget
(
self
,
action
:
#selector(
confirm
)
,
for
:
.
touchUpInside
)
let
item
=
UIBarButtonItem
(
customView
:
confirmBtn
)
navigationItem
.
rightBarButtonItem
=
item
}
}
...
...
@@ -205,7 +205,7 @@ open class MRAlbumListViewController: UIViewController {
collectionView
.
allowsMultipleSelection
=
maxCount
>
1
let
count
=
selectedAssests
.
count
-
maxCount
if
count
>
0
{
selectedAssests
.
remove
La
st
(
count
)
selectedAssests
.
remove
Fir
st
(
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
)
{
self
.
selectedAssests
.
append
(
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,10 +256,14 @@ open class MRAlbumListViewController: UIViewController {
/// 点击确定
@objc
open
func
confirm
()
{
ToastView
.
loading
()
requestImages
(
with
:
selectedAssests
,
size
:
maxImageSize
)
{
(
images
,
count
)
in
ToastView
.
hide
(
animate
:
false
)
self
.
didConfirm
?(
self
,
images
,
count
)
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
)
}
}
}
...
...
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