Commit 77da9609 authored by CZ1004's avatar CZ1004

【优化】部分代码优化

parent 401a24cd
......@@ -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()
}
}
......
......@@ -12,6 +12,7 @@ class CustomContactViewController: CNContactViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.allowsEditing = false
setupCancelButton()
}
......
......@@ -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{
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment