Commit ee053e70 authored by CZ1004's avatar CZ1004

优化闪屏问题

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