Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GeliBusinessPlatform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ljy
GeliBusinessPlatform
Commits
5caefc91
Commit
5caefc91
authored
Jun 30, 2021
by
lujunye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
32
parent
66f4791b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
GeliBusinessPlatform.xcworkspace/xcuserdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
...erdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
GeliBusinessPlatform/Other/HGImage/HGImagePickerController.swift
...inessPlatform/Other/HGImage/HGImagePickerController.swift
+17
-14
No files found.
GeliBusinessPlatform.xcworkspace/xcuserdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
View file @
5caefc91
No preview for this file type
GeliBusinessPlatform/Other/HGImage/HGImagePickerController.swift
View file @
5caefc91
...
...
@@ -30,13 +30,13 @@ class HGImagePickerController: UIViewController {
// 列出所有系统的智能相册
let
smartOptions
=
PHFetchOptions
()
let
smartAlbums
=
PHAssetCollection
.
fetchAssetCollections
(
with
:
.
smartAlbum
,
subtype
:
.
albumRegular
,
options
:
smartOptions
)
subtype
:
.
albumRegular
,
options
:
smartOptions
)
self
.
convertCollection
(
collection
:
smartAlbums
)
//列出所有用户创建的相册
let
userCollections
=
PHCollectionList
.
fetchTopLevelUserCollections
(
with
:
nil
)
self
.
convertCollection
(
collection
:
userCollections
as!
PHFetchResult
<
PHAssetCollection
>
)
as!
PHFetchResult
<
PHAssetCollection
>
)
//相册按包含的照片数量排序(降序)
self
.
items
.
sort
{
(
item1
,
item2
)
->
Bool
in
...
...
@@ -81,22 +81,25 @@ class HGImagePickerController: UIViewController {
private
func
convertCollection
(
collection
:
PHFetchResult
<
PHAssetCollection
>
){
for
i
in
0
..<
collection
.
count
{
//获取出但前相簿内的图片
let
resultsOptions
=
PHFetchOptions
()
resultsOptions
.
sortDescriptors
=
[
NSSortDescriptor
(
key
:
"creationDate"
,
ascending
:
false
)]
resultsOptions
.
predicate
=
NSPredicate
(
format
:
"mediaType = %d"
,
PHAssetMediaType
.
image
.
rawValue
)
let
c
=
collection
[
i
]
let
assetsFetchResult
=
PHAsset
.
fetchAssets
(
in
:
c
,
options
:
resultsOptions
)
//没有图片的空相簿不显示
if
assetsFetchResult
.
count
>
0
{
let
title
=
titleOfAlbumForChinse
(
title
:
c
.
localizedTitle
)
items
.
append
(
HGImageAlbumItem
(
title
:
title
,
fetchResult
:
assetsFetchResult
))
if
c
.
isKind
(
of
:
PHAssetCollection
.
self
){
let
assetsFetchResult
=
PHAsset
.
fetchAssets
(
in
:
c
,
options
:
resultsOptions
)
//没有图片的空相簿不显示
if
assetsFetchResult
.
count
>
0
{
let
title
=
titleOfAlbumForChinse
(
title
:
c
.
localizedTitle
)
items
.
append
(
HGImageAlbumItem
(
title
:
title
,
fetchResult
:
assetsFetchResult
))
}
}
}
}
//由于系统返回的相册集名称为英文,我们需要转换为中文
private
func
titleOfAlbumForChinse
(
title
:
String
?)
->
String
?
{
if
title
==
"Slo-mo"
{
...
...
@@ -133,8 +136,8 @@ class HGImagePickerController: UIViewController {
if
segue
.
identifier
==
"showImages"
{
//获取照片展示控制器
guard
let
imageCollectionVC
=
segue
.
destination
as?
HGImageCollectionViewController
,
let
cell
=
sender
as?
HGImagePickerCell
else
{
as?
HGImageCollectionViewController
,
let
cell
=
sender
as?
HGImagePickerCell
else
{
return
}
//设置回调函数
...
...
@@ -161,7 +164,7 @@ class HGImagePickerController: UIViewController {
extension
HGImagePickerController
:
UITableViewDelegate
,
UITableViewDataSource
{
//设置单元格内容
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
->
UITableViewCell
{
//同一形式的单元格重复使用,在声明时已注册
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"cell"
,
for
:
indexPath
)
as!
HGImagePickerCell
...
...
@@ -186,7 +189,7 @@ extension UIViewController {
//HGImagePicker提供给外部调用的接口,同于显示图片选择页面
func
presentHGImagePicker
(
maxSelected
:
Int
=
Int
.
max
,
completeHandler
:((
_
assets
:[
PHAsset
])
->
())?)
->
HGImagePickerController
?{
->
HGImagePickerController
?{
//获取图片选择视图控制器
if
let
vc
=
UIStoryboard
(
name
:
"HGImage"
,
bundle
:
Bundle
.
main
)
.
instantiateViewController
(
withIdentifier
:
"imagePickerVC"
)
...
...
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