Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PhoneManager
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yang
PhoneManager
Commits
77da9609
Commit
77da9609
authored
May 09, 2025
by
CZ1004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【优化】部分代码优化
parent
401a24cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
18 deletions
+59
-18
ContactBackupDetailViewController.swift
...ontact/Controller/ContactBackupDetailViewController.swift
+15
-5
CustomContactViewController.swift
...sion/Contact/Controller/CustomContactViewController.swift
+1
-0
ContactAllView.swift
...nager/Class/Session/Contact/View/All/ContactAllView.swift
+40
-12
BackupViewModel.swift
.../Session/Contact/View/Bac/ViewModel/BackupViewModel.swift
+3
-1
No files found.
PhoneManager/Class/Session/Contact/Controller/ContactBackupDetailViewController.swift
View file @
77da9609
...
...
@@ -6,6 +6,7 @@
//
import
Foundation
import
Contacts
class
ContactBackupDetailViewController
:
BaseViewController
{
...
...
@@ -157,6 +158,7 @@ extension ContactBackupDetailViewController:UITableViewDelegate,UITableViewDataS
return
20
}
func
setupCustomIndexView
()
{
customIndexView
=
nil
customIndexView
=
UIStackView
()
customIndexView
.
axis
=
.
vertical
customIndexView
.
alignment
=
.
center
...
...
@@ -166,9 +168,9 @@ extension ContactBackupDetailViewController:UITableViewDelegate,UITableViewDataS
self
.
customIndexView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
equalTo
(
self
.
tableView
.
snp
.
right
)
.
offset
(
0
)
make
.
top
.
equalTo
(
self
.
subTitleLabel
.
snp
.
bottom
)
.
offset
(
77
)
make
.
centerY
.
equalTo
(
self
.
view
.
snp
.
centerY
)
make
.
width
.
equalTo
(
15
*
RScreenW
())
make
.
height
.
equalTo
(
354
)
make
.
height
.
equalTo
(
self
.
sectionTitles
.
count
*
(
14
+
2
)
)
}
for
(
index
,
section
)
in
sectionTitles
.
enumerated
()
{
...
...
@@ -193,8 +195,17 @@ extension ContactBackupDetailViewController:UITableViewDelegate,UITableViewDataS
}
}
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
let
visibleRect
=
CGRect
(
origin
:
tableView
.
contentOffset
,
size
:
tableView
.
bounds
.
size
)
let
visiblePoint
=
CGPoint
(
x
:
visibleRect
.
midX
,
y
:
visibleRect
.
minY
)
// 获取可见区域的中心点,稍微向下偏移以更准确地检测当前可见的 section
let
visibleRect
=
CGRect
(
origin
:
tableView
.
contentOffset
,
size
:
tableView
.
bounds
.
size
)
// 将检测点从顶部边缘下移一些,例如下移10%的可见区域高度
let
adjustedY
=
visibleRect
.
minY
+
visibleRect
.
height
*
0.1
let
visiblePoint
=
CGPoint
(
x
:
visibleRect
.
midX
,
y
:
adjustedY
)
// 获取可见区域最顶部的单元格的 indexPath
if
let
visibleIndexPath
=
tableView
.
indexPathForRow
(
at
:
visiblePoint
)
{
let
newIndex
=
visibleIndexPath
.
section
if
newIndex
!=
selectedIndex
{
...
...
@@ -218,7 +229,6 @@ extension ContactBackupDetailViewController:UITableViewDelegate,UITableViewDataS
let
indexPath
=
IndexPath
(
row
:
0
,
section
:
index
)
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
top
,
animated
:
true
)
selectedIndex
=
index
updateIndexStyles
()
}
}
...
...
PhoneManager/Class/Session/Contact/Controller/CustomContactViewController.swift
View file @
77da9609
...
...
@@ -12,6 +12,7 @@ class CustomContactViewController: CNContactViewController {
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
self
.
allowsEditing
=
false
setupCancelButton
()
}
...
...
PhoneManager/Class/Session/Contact/View/All/ContactAllView.swift
View file @
77da9609
...
...
@@ -153,7 +153,7 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
}
else
{
self
.
selectedContacts
.
removeAll
(
where
:
{
$0
.
identifier
==
model
.
identifier
})
}
DispatchQueue
.
main
.
async
{
// 判断button是否显示
if
self
.
selectedContacts
.
count
>
0
{
...
...
@@ -205,9 +205,9 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
self
.
customIndexView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
equalTo
(
self
.
tableView
.
snp
.
right
)
.
offset
(
0
)
make
.
top
.
equalTo
(
self
.
subTitleLabel
.
snp
.
bottom
)
.
offset
(
77
)
make
.
centerY
.
equalTo
(
self
.
snp
.
centerY
)
make
.
width
.
equalTo
(
15
*
RScreenW
())
make
.
height
.
equalTo
(
354
)
make
.
height
.
equalTo
(
self
.
sectionTitles
.
count
*
(
14
+
2
)
)
}
for
(
index
,
section
)
in
sectionTitles
.
enumerated
()
{
...
...
@@ -232,8 +232,17 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
}
}
func
scrollViewDidScroll
(
_
scrollView
:
UIScrollView
)
{
let
visibleRect
=
CGRect
(
origin
:
tableView
.
contentOffset
,
size
:
tableView
.
bounds
.
size
)
let
visiblePoint
=
CGPoint
(
x
:
visibleRect
.
midX
,
y
:
visibleRect
.
minY
)
// 获取可见区域的中心点,稍微向下偏移以更准确地检测当前可见的 section
let
visibleRect
=
CGRect
(
origin
:
tableView
.
contentOffset
,
size
:
tableView
.
bounds
.
size
)
// 将检测点从顶部边缘下移一些,例如下移10%的可见区域高度
let
adjustedY
=
visibleRect
.
minY
+
visibleRect
.
height
*
0.1
let
visiblePoint
=
CGPoint
(
x
:
visibleRect
.
midX
,
y
:
adjustedY
)
// 获取可见区域最顶部的单元格的 indexPath
if
let
visibleIndexPath
=
tableView
.
indexPathForRow
(
at
:
visiblePoint
)
{
let
newIndex
=
visibleIndexPath
.
section
if
newIndex
!=
selectedIndex
{
...
...
@@ -257,7 +266,6 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
let
indexPath
=
IndexPath
(
row
:
0
,
section
:
index
)
tableView
.
scrollToRow
(
at
:
indexPath
,
at
:
.
top
,
animated
:
true
)
selectedIndex
=
index
updateIndexStyles
()
}
}
...
...
@@ -271,12 +279,32 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
guard
let
self
else
{
return
}
if
isSure
{
backupContactsByselect
{
// 备份完成后删除
self
.
deleteContacts
()
// 删除之前弹出是否真的需要删除
let
alertVc
=
ContactDeleteAlertView
()
alertVc
.
frame
=
(
self
.
responderViewController
()?
.
view
.
bounds
)
!
cWindow
?
.
addSubview
(
alertVc
)
alertVc
.
sureCallBack
=
{[
weak
self
]
isSure
in
guard
let
self
else
{
return
}
if
isSure
{
// 提示是否删除
self
.
deleteContacts
()
}
}
}
}
else
{
// 如果不备份,直接删除
self
.
deleteContacts
()
// 删除之前弹出是否真的需要删除
let
alertVc
=
ContactDeleteAlertView
()
alertVc
.
frame
=
(
self
.
responderViewController
()?
.
view
.
bounds
)
!
cWindow
?
.
addSubview
(
alertVc
)
alertVc
.
sureCallBack
=
{[
weak
self
]
isSure
in
guard
let
self
else
{
return
}
if
isSure
{
// 提示是否删除
self
.
deleteContacts
()
}
}
}
}
}
...
...
@@ -284,15 +312,15 @@ extension ContactAllView : UITableViewDataSource,UITableViewDelegate {
func
backupContactsByselect
(
success
:
@escaping
()
->
Void
){
// 开始备份联系人,备份完成提示
let
vm
=
BackupViewModel
()
vm
.
backupPartialContacts
(
self
.
selectedContacts
)
{
finised
,
error
in
vm
.
backupPartialContacts
(
self
.
dataSourceModel
)
{
finised
,
error
in
if
finised
{
// 备份成功
success
()
DispatchQueue
.
main
.
async
{
let
buAlertVc
=
ContactBackUpCompletedAlertView
(
frame
:
(
cWindow
?
.
bounds
)
!
)
cWindow
?
.
addSubview
(
buAlertVc
)
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
1
)
{
buAlertVc
.
removeFromSuperview
()
success
()
}
}
}
else
{
...
...
PhoneManager/Class/Session/Contact/View/Bac/ViewModel/BackupViewModel.swift
View file @
77da9609
...
...
@@ -99,7 +99,9 @@ class BackupViewModel {
decoder
.
dateDecodingStrategy
=
.
iso8601
// 尝试解码为 BackupInfoModel 数组
let
backupInfos
=
try
decoder
.
decode
([
BackupInfoModel
]
.
self
,
from
:
jsonData
)
completion
(
backupInfos
,
nil
)
// 根据时间倒序下
let
sortedModels
=
backupInfos
.
sorted
{
$0
.
backupTime
>
$1
.
backupTime
}
completion
(
sortedModels
,
nil
)
}
catch
{
Print
(
error
.
localizedDescription
)
completion
(
nil
,
error
)
...
...
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