Commit ee053e70 authored by CZ1004's avatar CZ1004

优化闪屏问题

parent c41d849d
...@@ -92,10 +92,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -92,10 +92,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.dataSiFileSize = model.titleModelArray[1].allFileSize self.dataSiFileSize = model.titleModelArray[1].allFileSize
self.dataScFileSize = model.otherModelArray[1].allFileSize self.dataScFileSize = model.otherModelArray[1].allFileSize
// 更新视频数据 // 更新视频数据
Print("更新视频数据")
let videoCount = model.otherModelArray[0].assets.count let videoCount = model.otherModelArray[0].assets.first?.count
// 查看是否有更新 // 查看是否有更新
if videoCount != PhotoAndVideoMananger.mananger.videoAssets.count { if videoCount != PhotoAndVideoMananger.mananger.videoAssets.count {
Print("更新视频数据")
// 先移除数据 // 先移除数据
model.otherModelArray[0].assets.removeAll() model.otherModelArray[0].assets.removeAll()
model.otherModelArray[0].allFileSize = 0 model.otherModelArray[0].allFileSize = 0
...@@ -140,9 +141,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -140,9 +141,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
Print("更新截图数据")
let screeshotCount = model.otherModelArray[2].assets.count let screeshotCount = model.otherModelArray[2].assets.first?.count
if screeshotCount != PhotoAndVideoMananger.mananger.screenShotAssets.count { if screeshotCount != PhotoAndVideoMananger.mananger.screenShotAssets.count {
Print("更新截图数据")
// 先移除数据 // 先移除数据
model.otherModelArray[2].assets.removeAll() model.otherModelArray[2].assets.removeAll()
model.otherModelArray[2].allFileSize = 0 model.otherModelArray[2].allFileSize = 0
...@@ -165,9 +167,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -165,9 +167,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
Print("更新照片数据")
let imageCount = model.otherModelArray[4].assets.count let imageCount = model.otherModelArray[4].assets.first?.count
if imageCount != PhotoAndVideoMananger.mananger.otherAssets.count{ if imageCount != PhotoAndVideoMananger.mananger.otherAssets.count{
Print("更新照片数据")
PhotoAndVideoMananger.mananger.dealImageAssetData { data in PhotoAndVideoMananger.mananger.dealImageAssetData { data in
var dataArray : [AssetModel] = [] var dataArray : [AssetModel] = []
for item in data { for item in data {
...@@ -224,6 +227,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -224,6 +227,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.dataArrayDu.remove(at: self.dataArrayDu.count - 1) self.dataArrayDu.remove(at: self.dataArrayDu.count - 1)
model.titleModelArray[0].allFileSize = self.dataDuFileSize + Double(fileSize) model.titleModelArray[0].allFileSize = self.dataDuFileSize + Double(fileSize)
PhotoDataManager.manager.saveToFileSystem(model: model) PhotoDataManager.manager.saveToFileSystem(model: model)
let dataUpdated = Notification.Name("HomeDupImageResourceUpdate") let dataUpdated = Notification.Name("HomeDupImageResourceUpdate")
NotificationCenter.default.post(name: dataUpdated, object: nil) NotificationCenter.default.post(name: dataUpdated, object: nil)
...@@ -232,10 +236,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -232,10 +236,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
PhotoAndVideoMananger.mananger.calculateTotalSize(of: PhotoAndVideoMananger.mananger.getPHAsssetwithIDs(ids: dataArray2)!,progress: { fileSize, index in PhotoAndVideoMananger.mananger.calculateTotalSize(of: PhotoAndVideoMananger.mananger.getPHAsssetwithIDs(ids: dataArray2)!,progress: { fileSize, index in
// 不做处理 // 不做处理
}, completion: {[model = model]fileSize,index in }, completion: {[dataArray2 = dataArray2] fileSize,index in
if dataArray2.count > 0 { if dataArray2.count > 0 {
self.dataArraySi.append(dataArray2) self.dataArraySi.append(dataArray2)
model.titleModelArray[0].assets = self.dataArraySi model.titleModelArray[1].assets = self.dataArraySi
self.dataArraySi.remove(at: self.dataArraySi.count - 1) self.dataArraySi.remove(at: self.dataArraySi.count - 1)
model.titleModelArray[1].allFileSize = self.dataSiFileSize + Double(fileSize) model.titleModelArray[1].allFileSize = self.dataSiFileSize + Double(fileSize)
...@@ -271,7 +275,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -271,7 +275,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
PhotoAndVideoMananger.mananger.calculateTotalSize(of: PhotoAndVideoMananger.mananger.getPHAsssetwithIDs(ids: dataArray2)!,progress: { fileSiez, index in PhotoAndVideoMananger.mananger.calculateTotalSize(of: PhotoAndVideoMananger.mananger.getPHAsssetwithIDs(ids: dataArray2)!,progress: { fileSiez, index in
// 不做处理 // 不做处理
}, completion: {[model = model] fileSize,index in }, completion: {[dataArray2 = dataArray2] fileSize,index in
if dataArray2.count > 0 { if dataArray2.count > 0 {
self.dataArraySc.append(dataArray2) self.dataArraySc.append(dataArray2)
model.titleModelArray[0].assets = self.dataArraySc model.titleModelArray[0].assets = self.dataArraySc
......
{
"images" : [
{
"filename" : "img_photo__home_defpage.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_photo__home_defpage@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_photo__home_defpage@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -19,7 +19,7 @@ class CompressSelectCell : UICollectionViewCell { ...@@ -19,7 +19,7 @@ class CompressSelectCell : UICollectionViewCell {
var model : ResourceModel? { var model : ResourceModel? {
didSet{ didSet{
guard let model = self.model else {return} guard let model = self.model else {return}
self.backImageView.image = nil self.backImageView.image = UIImage()
let viewModel = CompressViewModel() let viewModel = CompressViewModel()
viewModel.getImageFromAssetIdentifier(identifier: model.ident) {[weak self] image in viewModel.getImageFromAssetIdentifier(identifier: model.ident) {[weak self] image in
guard let self else { return} guard let self else { return}
......
...@@ -348,4 +348,6 @@ class CompressCompletedViewController : BaseViewController{ ...@@ -348,4 +348,6 @@ class CompressCompletedViewController : BaseViewController{
setUI() setUI()
self.animationView.play(fromProgress: 0, toProgress: 1,loopMode: .playOnce) self.animationView.play(fromProgress: 0, toProgress: 1,loopMode: .playOnce)
} }
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import Foundation import Foundation
import SnapKit import SnapKit
import Photos import Photos
import SVProgressHUD
class CompressController : BaseViewController { class CompressController : BaseViewController {
...@@ -106,7 +107,7 @@ class CompressController : BaseViewController { ...@@ -106,7 +107,7 @@ class CompressController : BaseViewController {
/// 获取当前页面数据 /// 获取当前页面数据
func getViewData(){ func getViewData(){
self.resourceData.removeAll() self.resourceData.removeAll()
let datas = Singleton.shared.resourceModel let datas = Singleton.shared.resourceModel
if datas.count > 0 { if datas.count > 0 {
// 这里需要重新排序下 // 这里需要重新排序下
if self.currentSort == 0 { if self.currentSort == 0 {
...@@ -119,9 +120,12 @@ class CompressController : BaseViewController { ...@@ -119,9 +120,12 @@ class CompressController : BaseViewController {
self.resourceData = datas.sorted {$0.createDate < $1.createDate } self.resourceData = datas.sorted {$0.createDate < $1.createDate }
} }
}else{ }else{
SVProgressHUD.show()
CompressViewModel().getAllPhotosToAssets(sortType: self.currentSort, assetType: self.currentResourceType) { [weak self] models in CompressViewModel().getAllPhotosToAssets(sortType: self.currentSort, assetType: self.currentResourceType) { [weak self] models in
guard let self else {return} guard let self else {return}
self.resourceData = models self.resourceData = models
Singleton.shared.resourceModel = self.resourceData
SVProgressHUD.dismiss()
} }
} }
} }
...@@ -134,6 +138,10 @@ class CompressController : BaseViewController { ...@@ -134,6 +138,10 @@ class CompressController : BaseViewController {
self.collectionView.reloadData() self.collectionView.reloadData()
} }
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
SVProgressHUD.dismiss()
}
} }
......
...@@ -17,6 +17,9 @@ class HomePhotosDetailViewController : BaseViewController { ...@@ -17,6 +17,9 @@ class HomePhotosDetailViewController : BaseViewController {
var mediaType : PhotsFileType? var mediaType : PhotsFileType?
var imageCache = NSCache<NSString, UIImage>()
@MainActor required init?(coder: NSCoder) { @MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
...@@ -119,7 +122,10 @@ class HomePhotosDetailViewController : BaseViewController { ...@@ -119,7 +122,10 @@ class HomePhotosDetailViewController : BaseViewController {
self.selectedModel.removeAll() self.selectedModel.removeAll()
} }
DispatchQueue.main.async { DispatchQueue.main.async {
self.collectionView.reloadData()
UIView.transition(with: self.collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.collectionView.reloadData()
}, completion: nil)
if self.selectedModel.count > 0 { if self.selectedModel.count > 0 {
self.deleteButton.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1) self.deleteButton.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
...@@ -161,10 +167,29 @@ class HomePhotosDetailViewController : BaseViewController { ...@@ -161,10 +167,29 @@ class HomePhotosDetailViewController : BaseViewController {
if self.selectedModel.count == 0 { if self.selectedModel.count == 0 {
self.collectionView.reloadData() self.collectionView.reloadData()
} }
}
func getImageFromCache(model: AssetModel,completed:@escaping (UIImage)->Void){
let cachedImage = self.imageCache.object(forKey: model.localIdentifier as NSString)
if cachedImage != nil {
completed(cachedImage!)
}
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [model.localIdentifier], options: nil)
let assetsArray = fetchResult.objects(at: IndexSet(0..<fetchResult.count))
let options = PHImageRequestOptions()
options.isNetworkAccessAllowed = true
options.isSynchronous = false
PHImageManager.default().requestImage(for: assetsArray.first!, targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: options) { (image, info) in
completed(image ?? UIImage())
}
} }
} }
extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UICollectionViewDelegate { extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UICollectionViewDelegate {
func numberOfSections(in collectionView: UICollectionView) -> Int { func numberOfSections(in collectionView: UICollectionView) -> Int {
...@@ -180,10 +205,17 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -180,10 +205,17 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomePhotosDetailCollectionCell", for: indexPath) as! HomePhotosDetailCollectionCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomePhotosDetailCollectionCell", for: indexPath) as! HomePhotosDetailCollectionCell
cell.resourceIdent = self.resourceData[indexPath.row] cell.resourceIdent = self.resourceData[indexPath.row]
// 这里做缓存
cell.backImageView.image = UIImage()
self.getImageFromCache(model: self.resourceData[indexPath.row]) {[weak self] image in
guard self != nil else {return}
DispatchQueue.main.async {
cell.backImageView.image = image
}
}
cell.currentOrder = indexPath.row cell.currentOrder = indexPath.row
if self.selectedModel.contains(where: { $0.localIdentifier == cell.resourceIdent.localIdentifier }) { if self.selectedModel.contains(where: { $0.localIdentifier == self.resourceData[indexPath.row].localIdentifier }) {
cell.choose = true cell.choose = true
}else{ }else{
cell.choose = false cell.choose = false
......
...@@ -121,7 +121,10 @@ class HomeVideoDetailController :BaseViewController { ...@@ -121,7 +121,10 @@ class HomeVideoDetailController :BaseViewController {
self.selectedModel.removeAll() self.selectedModel.removeAll()
} }
DispatchQueue.main.async { DispatchQueue.main.async {
self.collectionView.reloadData()
UIView.transition(with: self.collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.collectionView.reloadData()
}, completion: nil)
if self.selectedModel.count > 0 { if self.selectedModel.count > 0 {
self.deleteButton.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1) self.deleteButton.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
...@@ -150,6 +153,8 @@ class HomeVideoDetailController :BaseViewController { ...@@ -150,6 +153,8 @@ class HomeVideoDetailController :BaseViewController {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = .white view.backgroundColor = .white
self.navigationController?.navigationBar.isHidden = true self.navigationController?.navigationBar.isHidden = true
setUI() setUI()
} }
...@@ -182,6 +187,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -182,6 +187,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
cell.resourceIdent = self.resourceData[indexPath.row] cell.resourceIdent = self.resourceData[indexPath.row]
cell.currentOrder = indexPath.row cell.currentOrder = indexPath.row
cell.backImageView.image = nil
if self.selectedModel.contains(where: { $0.localIdentifier == cell.resourceIdent!.localIdentifier }) { if self.selectedModel.contains(where: { $0.localIdentifier == cell.resourceIdent!.localIdentifier }) {
cell.choose = true cell.choose = true
}else{ }else{
......
...@@ -239,6 +239,16 @@ extension HomeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UICol ...@@ -239,6 +239,16 @@ extension HomeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UICol
case 0: case 0:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeTitleCollectionCell.identifiers, for: indexPath) as! HomeTitleCollectionCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeTitleCollectionCell.identifiers, for: indexPath) as! HomeTitleCollectionCell
cell.model = model?.titleModelArray[indexPath.row] cell.model = model?.titleModelArray[indexPath.row]
cell.homeTititlAction = {[weak self] idx in
guard let self = self else { return }
let smodel = self.model?.titleModelArray[indexPath.row]
if indexPath.row == 0 {
self.titleCallBack(smodel!,.duplicates)
}else{
self.titleCallBack(smodel!,.similar)
}
}
if indexPath.row == 0 { if indexPath.row == 0 {
self.dupHeadCell = cell self.dupHeadCell = cell
}else{ }else{
......
...@@ -142,9 +142,11 @@ class HomeInfoTableViewCell:UITableViewCell { ...@@ -142,9 +142,11 @@ class HomeInfoTableViewCell:UITableViewCell {
} }
} }
if collectionView != nil {
collectionView?.reloadData() UIView.transition(with: collectionView!, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.collectionView?.reloadData()
}, completion: nil)
}
callBack("changgeSeleted") callBack("changgeSeleted")
} }
......
...@@ -159,12 +159,11 @@ class HomeOtherCollectionCell: UICollectionViewCell { ...@@ -159,12 +159,11 @@ class HomeOtherCollectionCell: UICollectionViewCell {
self.imageView.image = thumbnailImage self.imageView.image = thumbnailImage
} }
} else { } else {
self.imageView.image = UIImage(named: "img_photo__home_defpage")
print("无法获取图片") print("无法获取图片")
} }
} }
} }
} }
} }
......
...@@ -27,24 +27,7 @@ class HomePhotosDetailCollectionCell : UICollectionViewCell { ...@@ -27,24 +27,7 @@ class HomePhotosDetailCollectionCell : UICollectionViewCell {
} }
} }
var resourceIdent : AssetModel = AssetModel(localIdentifier: "", assetSize: 0.0, createDate: Date()) { var resourceIdent : AssetModel?
didSet{
DispatchQueue.global().async {
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [self.resourceIdent.localIdentifier], options: nil)
let assetsArray = fetchResult.objects(at: IndexSet(0..<fetchResult.count))
let options = PHImageRequestOptions()
options.isNetworkAccessAllowed = true
options.isSynchronous = false
PHImageManager.default().requestImage(for: assetsArray.first!, targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFill, options: options) { (image, info) in
DispatchQueue.main.async {
if let image = image {
self.backImageView.image = image
}
}
}
}
}
}
var currentOrder : Int = 0 var currentOrder : Int = 0
...@@ -81,7 +64,7 @@ class HomePhotosDetailCollectionCell : UICollectionViewCell { ...@@ -81,7 +64,7 @@ class HomePhotosDetailCollectionCell : UICollectionViewCell {
@objc func cellClick(){ @objc func cellClick(){
cellCallBack(self.resourceIdent,self.currentOrder) cellCallBack(self.resourceIdent!,self.currentOrder)
} }
......
...@@ -22,6 +22,9 @@ class HomeTitleCollectionCell:UICollectionViewCell { ...@@ -22,6 +22,9 @@ class HomeTitleCollectionCell:UICollectionViewCell {
private var assetsModels:[ImageCollectionModel] = [] private var assetsModels:[ImageCollectionModel] = []
var homeTititlAction:((_ idx:Int)->Void) = { idx in}
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
...@@ -177,7 +180,11 @@ extension HomeTitleCollectionCell:UICollectionViewDelegate,UICollectionViewDataS ...@@ -177,7 +180,11 @@ extension HomeTitleCollectionCell:UICollectionViewDelegate,UICollectionViewDataS
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 10 // 设置列间距 return 10 // 设置列间距
} }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
homeTititlAction(1)
}
} }
...@@ -15,18 +15,21 @@ class PMShowImgCell: UICollectionViewCell { ...@@ -15,18 +15,21 @@ class PMShowImgCell: UICollectionViewCell {
didSet { didSet {
iconView.image = icon iconView.image = icon
var size = icon.size var size = icon.size
if size.height < size.width { if size.width != 0 && size.height != 0 {
let width = self.width if size.height < size.width {
size = CGSize(width: width, height: size.height * (width/size.width) ) let width = self.width
}else{ size = CGSize(width: width, height: size.height * (width/size.width) )
let width = self.width }else{
let height = size.height * (width/size.width) let width = self.width
if height > self.height { let height = size.height * (width/size.width)
size = CGSize(width: width * (self.height/height), height: height ) if height > self.height {
}else { size = CGSize(width: width * (self.height/height), height: height )
size = CGSize(width: width, height: height ) }else {
size = CGSize(width: width, height: height )
}
} }
} }
iconView.snp.remakeConstraints { make in iconView.snp.remakeConstraints { make in
make.centerX.centerY.equalToSuperview() make.centerX.centerY.equalToSuperview()
make.size.equalTo(size) make.size.equalTo(size)
......
...@@ -169,11 +169,11 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -169,11 +169,11 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
if collectionView == MaxCollection { if collectionView == MaxCollection {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowImgCellID, for: indexPath) as! PMShowImgCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowImgCellID, for: indexPath) as! PMShowImgCell
cell.icon = self.homeDataSource![indexPath.row].image! cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage()
return cell return cell
}else { }else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell
cell.icon = self.homeDataSource![indexPath.row].image cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage()
cell.isCurrent = (self.currentIdx == indexPath.row) cell.isCurrent = (self.currentIdx == indexPath.row)
return cell return cell
} }
......
...@@ -816,6 +816,8 @@ class PhotoAndVideoMananger { ...@@ -816,6 +816,8 @@ class PhotoAndVideoMananger {
data.append(AssetModel.init(localIdentifier: item.localIdentifier, assetSize: self.findAssetSize(asset: item), createDate: item.creationDate!)) data.append(AssetModel.init(localIdentifier: item.localIdentifier, assetSize: self.findAssetSize(asset: item), createDate: item.creationDate!))
} }
var finalData : [[AssetModel]] = [] var finalData : [[AssetModel]] = []
// 按照大小排序下
data = data.sorted{ $0.assetSize < $1.assetSize }
finalData.append(data) finalData.append(data)
completionHandler(finalData) completionHandler(finalData)
} }
......
...@@ -11,6 +11,7 @@ target 'PhoneManager' do ...@@ -11,6 +11,7 @@ target 'PhoneManager' do
pod 'SnapKit' pod 'SnapKit'
pod 'HXPhotoPicker' pod 'HXPhotoPicker'
pod 'OpenCV' pod 'OpenCV'
pod 'SVProgressHUD'
end end
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