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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
+7
-4
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
+21
-3
No files found.
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
View file @
73a54df2
...
@@ -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
()
}
}
}
}
...
...
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
View file @
73a54df2
...
@@ -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
.
remove
La
st
(
count
)
selectedAssests
.
remove
Fir
st
(
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
)
}
}
}
}
}
...
...
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