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
bb9f04c8
authored
Sep 15, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正luo ji
parent
f7bd031b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
25 deletions
+57
-25
MRFramework/MRFramework/UIControls/Album/Interface/MRAlbumCell.swift
+10
-2
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
+39
-21
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
+8
-2
No files found.
MRFramework/MRFramework/UIControls/Album/Interface/MRAlbumCell.swift
View file @
bb9f04c8
...
...
@@ -16,10 +16,11 @@ public final class MRAlbumCell: UICollectionViewCell {
public
static
var
selectedCheckboxOptions
:
MRCheckBoxOptions
=
.
defaultCheck
(
checkboxSize
)
public
let
imageView
=
UIImageView
()
public
let
selectedMask
=
UIView
()
public
let
selectedMask
=
UI
Image
View
()
public
let
checkbox
=
UIButton
()
public
var
check
:
((
_
cell
:
MRAlbumCell
)
->
Void
)?
public
var
didTapOnImage
:
((
_
cell
:
MRAlbumCell
)
->
Void
)?
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
...
...
@@ -45,13 +46,20 @@ public final class MRAlbumCell: UICollectionViewCell {
@objc
private
func
checkButtonPressed
(
_
sender
:
UIButton
)
{
check
?(
self
)
}
@objc
private
func
imageDidTap
(
_
sender
:
UITapGestureRecognizer
)
{
didTapOnImage
?(
self
)
}
}
extension
MRAlbumCell
{
private
func
setupViews
()
{
let
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
imageDidTap(_:)
)
)
imageView
.
addGestureRecognizer
(
tap
)
imageView
.
isUserInteractionEnabled
=
true
selectedMask
.
backgroundColor
=
.
init
(
0xffffff
,
alpha
:
0.3
)
selectedMask
.
isUserInteractionEnabled
=
false
selectedMask
.
isHidden
=
true
checkbox
.
setImage
(
MRCheckBoxImage
.
image
(
with
:
MRAlbumCell
.
deselectedCheckboxOptions
),
for
:
.
normal
)
...
...
MRFramework/MRFramework/UIControls/Album/MRAlbumDetailViewController.swift
View file @
bb9f04c8
...
...
@@ -21,6 +21,10 @@ open class MRAlbumDetailViewController: UIViewController {
static
let
requestQueue
=
DispatchQueue
(
label
:
"com.MRAblum.detail.queue"
)
public
static
var
checkboxSize
=
CGSize
(
width
:
40
,
height
:
40
)
public
static
var
unCheckOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
clear
)
public
static
var
checkedOptions
:
MRCheckBoxOptions
=
.
defaultCheck
(
checkboxSize
)
public
var
confirm
:
((
_
vc
:
MRAlbumDetailViewController
,
_
isSelected
:
Bool
)
->
Void
)?
public
var
assest
:
PHAsset
!
...
...
@@ -31,8 +35,6 @@ open class MRAlbumDetailViewController: UIViewController {
private
let
imageView
=
UIImageView
()
private
let
checkButton
=
UIButton
(
type
:
.
custom
)
private
let
checkboxSize
=
CGSize
(
width
:
40
,
height
:
40
)
private
var
state
:
AlbumDetailState
=
.
none
{
didSet
{
stateDidChange
()
...
...
@@ -65,6 +67,11 @@ open class MRAlbumDetailViewController: UIViewController {
open
override
var
prefersStatusBarHidden
:
Bool
{
return
true
}
open
override
func
viewDidLayoutSubviews
()
{
super
.
viewDidLayoutSubviews
()
setupLayouts
()
}
}
extension
MRAlbumDetailViewController
{
...
...
@@ -92,6 +99,7 @@ extension MRAlbumDetailViewController {
@objc
private
func
confirmButtonDidPress
(
_
sender
:
UIButton
)
{
confirm
?(
self
,
isSelected
)
navigationController
?
.
popViewController
(
animated
:
true
)
}
}
...
...
@@ -130,6 +138,11 @@ extension MRAlbumDetailViewController {
view
.
addSubview
(
scrollView
)
scrollView
.
addSubview
(
imageView
)
view
.
addSubview
(
checkButton
)
checkButton
.
snp
.
makeConstraints
{
(
make
)
in
make
.
right
.
bottom
.
equalToSuperview
()
.
offset
(
-
10
)
make
.
size
.
equalTo
(
MRAlbumDetailViewController
.
checkboxSize
)
}
view
.
setNeedsLayout
()
addConfirmButton
()
setupMainViews
()
...
...
@@ -144,6 +157,8 @@ extension MRAlbumDetailViewController {
scrollView
.
zoomScale
=
1
scrollView
.
maximumZoomScale
=
3
scrollView
.
minimumZoomScale
=
1
scrollView
.
delegate
=
self
scrollView
.
bounces
=
true
let
singleTap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
singleTap(_:)
)
)
singleTap
.
numberOfTapsRequired
=
1
...
...
@@ -153,30 +168,25 @@ extension MRAlbumDetailViewController {
doubleTap
.
numberOfTapsRequired
=
2
doubleTap
.
numberOfTouchesRequired
=
1
singleTap
.
require
(
toFail
:
doubleTap
)
imageView
.
addGestureRecognizer
(
singleTap
)
imageView
.
addGestureRecognizer
(
doubleTap
)
imageView
.
isUserInteractionEnabled
=
true
imageView
.
contentMode
=
.
scaleAspectFit
let
unCheckOptions
:
MRCheckBoxOptions
=
.
custom
(
size
:
checkboxSize
,
backgroundColor
:
.
clear
)
let
checkedOptions
:
MRCheckBoxOptions
=
.
defaultCheck
(
checkboxSize
)
checkButton
.
setImage
(
MRCheckBoxImage
.
image
(
with
:
unCheckOptions
),
for
:
.
normal
)
checkButton
.
setImage
(
MRCheckBoxImage
.
image
(
with
:
checkedOptions
),
for
:
.
selected
)
checkButton
.
setImage
(
MRCheckBoxImage
.
image
(
with
:
MRAlbumDetailViewController
.
unCheckOptions
),
for
:
.
normal
)
checkButton
.
setImage
(
MRCheckBoxImage
.
image
(
with
:
MRAlbumDetailViewController
.
checkedOptions
),
for
:
.
selected
)
checkButton
.
addTarget
(
self
,
action
:
#selector(
checkboxDidPress(_:)
)
,
for
:
.
touchUpInside
)
checkButton
.
isSelected
=
isSelected
}
private
func
setupLayouts
()
{
scrollView
.
snp
.
makeConstraints
{
(
make
)
in
make
.
edges
.
equalToSuperview
()
}
imageView
.
snp
.
makeConstraints
{
(
make
)
in
make
.
edges
.
equalToSuperview
()
}
checkButton
.
snp
.
makeConstraints
{
(
make
)
in
make
.
right
.
bottom
.
equalToSuperview
()
.
offset
(
-
10
)
make
.
size
.
equalTo
(
checkboxSize
)
}
view
.
setNeedsLayout
()
scrollView
.
frame
=
view
.
bounds
imageView
.
frame
=
scrollView
.
bounds
// checkButton.frame = CGRect(x: view.frame.maxX - checkboxSize.width,
// y: view.frame.maxY - checkboxSize.height - bottomPadding,
// width: checkboxSize.width,
// height: checkboxSize.height)
}
private
func
resizeImageView
()
{
...
...
@@ -185,10 +195,8 @@ extension MRAlbumDetailViewController {
let
hradio
=
image
.
size
.
height
/
UIScreen
.
main
.
bounds
.
height
let
radio
=
max
(
wradio
,
hradio
)
let
size
=
image
.
size
*
(
1
/
radio
)
imageView
.
snp
.
remakeConstraints
{
(
make
)
in
make
.
size
.
equalTo
(
size
)
make
.
center
.
equalToSuperview
()
}
imageView
.
frame
=
CGRect
(
origin
:
CGPoint
.
zero
,
size
:
size
)
imageView
.
center
=
scrollView
.
center
}
}
...
...
@@ -207,4 +215,14 @@ extension MRAlbumDetailViewController: UIScrollViewDelegate {
public
func
viewForZooming
(
in
scrollView
:
UIScrollView
)
->
UIView
?
{
return
imageView
}
public
func
scrollViewDidZoom
(
_
scrollView
:
UIScrollView
)
{
var
centerX
=
scrollView
.
center
.
x
var
centerY
=
scrollView
.
center
.
y
centerX
=
scrollView
.
contentSize
.
width
>
scrollView
.
frame
.
size
.
width
?
scrollView
.
contentSize
.
width
/
2
:
centerX
centerY
=
scrollView
.
contentSize
.
height
>
scrollView
.
frame
.
size
.
height
?
scrollView
.
contentSize
.
height
/
2
:
centerY
imageView
.
center
=
CGPoint
(
x
:
centerX
,
y
:
centerY
)
}
}
MRFramework/MRFramework/UIControls/Album/MRAlbumListViewController.swift
View file @
bb9f04c8
...
...
@@ -103,7 +103,7 @@ open class MRAlbumListViewController: UIViewController {
thumbImageSize
=
layout
?
.
itemSize
??
CGSize
.
zero
}
open
func
cellSetting
(
_
cell
:
UICollectionViewCell
,
at
indexPath
:
IndexPath
)
{
open
func
cellSetting
(
_
c
ollectionView
:
UICollectionView
,
c
ell
:
UICollectionViewCell
,
at
indexPath
:
IndexPath
)
{
if
let
cell
=
cell
as?
MRAlbumCell
,
let
assest
=
assests
?[
indexPath
.
row
]
{
requestImage
(
with
:
assest
,
size
:
thumbImageSize
*
UIScreen
.
main
.
scale
)
{
image
,
isTemp
in
if
!
isTemp
{
...
...
@@ -117,6 +117,9 @@ open class MRAlbumListViewController: UIViewController {
self
.
didClickOnCellCheck
(
cell
,
at
:
indexPath
)
}
}
cell
.
didTapOnImage
=
{
_
in
self
?
.
didSelectItem
(
collectionView
,
at
:
indexPath
)
}
}
}
...
...
@@ -193,6 +196,9 @@ open class MRAlbumListViewController: UIViewController {
}
else
if
!
isSelected
{
self
.
selectedAssests
.
removeAll
(
where
:
{
$0
==
assest
})
}
if
let
cell
=
collectionView
.
cellForItem
(
at
:
indexPath
)
{
cell
.
isSelected
=
isSelected
}
}
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
...
...
@@ -414,7 +420,7 @@ extension MRAlbumListViewController: UICollectionViewDataSource {
open
func
collectionView
(
_
collectionView
:
UICollectionView
,
cellForItemAt
indexPath
:
IndexPath
)
->
UICollectionViewCell
{
let
cell
=
collectionView
.
mr
.
dequeueCell
(
MRAlbumCell
.
self
,
for
:
indexPath
)
cellSetting
(
cell
,
at
:
indexPath
)
cellSetting
(
c
ollectionView
,
cell
:
c
ell
,
at
:
indexPath
)
return
cell
}
}
...
...
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