Pārlūkot izejas kodu

修改缩略图实现方式,由collectionview 改为scrollvie

胡志强 3 gadi atpakaļ
vecāks
revīzija
32663ff240

+ 1 - 1
BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

@@ -70,7 +70,7 @@ class BFVoiceRecordManager: NSObject {
         let noiseFilePath = recorderFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
         voiceModel?.wavFilePath = noiseFilePath
 
-        BFLog(1, message: "\(debugHeader)开始录音::: \(recorderFilePath)")
+//        BFLog(1, message: "\(debugHeader)开始录音::: \(recorderFilePath)")
         audioRecorder?.startRecord(recorderFilePath)
     }
 

+ 25 - 30
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -119,7 +119,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             return
         }
         cameraProgressV?.recordItem = recordItem
-        cameraProgressV?.collectionV.reloadData()
+        resetThumbImg()
         
         initplayer()
 
@@ -128,7 +128,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             cameraProgressV?.isHidden = false
             progreddL?.isHidden = false
             progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
-            cameraProgressV?.collectionV.scrollRectToVisible(CGRect(x: (cameraProgressV?.collectionV.contentSize.width)! - 1, y: (cameraProgressV?.collectionV.contentSize.height)! - 1, width: 1, height: 1), animated: false)
+            cameraProgressV?.progressView.scrollRectToVisible(CGRect(x: (cameraProgressV?.progressView.contentSize.width)! - 1, y: (cameraProgressV?.progressView.contentSize.height)! - 1, width: 1, height: 1), animated: false)
             dele?.isEndPlay = true
         }else {
             currentAssetProgress = .zero
@@ -170,7 +170,8 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
         }
         
         playerCoverIV.isHidden = true
-
+        recordFinishedResult = false
+        
         super.startRecord()
 
         startTime = Date()
@@ -213,6 +214,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
     
     override func endRecord(){
         super.endRecord()
+
         writerlock = true
         timerr?.invalidate()
         timerr = nil
@@ -227,7 +229,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
                     if let finalPath = newPath, finalPath.count > 0 {
                         let dur = AVURLAsset(url: URL(fileURLWithPath: finalPath))
                         wself.videoModel.timelineCMOut = wself.videoModel.timelineCMIn + CMTime(seconds: dur.duration.seconds, preferredTimescale: 1000)
-                        BFLog(1, message: "拍摄文件时长:\(wself.videoModel.timelineCMIn.seconds)~\(wself.videoModel.timelineCMOut.seconds),  \(dur.duration.seconds)")
+                        BFLog(1, message: "文件时长camera:\(wself.recordItem?.videoStickers.count ?? 0),   \(wself.videoModel.timelineCMIn.seconds)~\(wself.videoModel.timelineCMOut.seconds),  \(dur.duration.seconds)")
                         wself.videoModel.locationPath = finalPath
                         if (wself.videoModel.timelineCMOut - wself.videoModel.timelineCMIn).seconds <= 1 {
                             wself.videoModel.locationPath = "nil"
@@ -239,7 +241,6 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
                                 // 代表录制成功了
                                 wself.currentAssetProgress = wself.videoModel.timelineCMOut
                                 wself.recordEndCallBack?(true, wself.videoModel)
-                                BFLog(1, message: "摄像成功")
                             }
                         }
                     }else{
@@ -265,6 +266,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
     }
     
     override func recordFinished(isSuccess:Bool) {
+
         recordFinishedResult = isSuccess
         
         //
@@ -279,22 +281,16 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
                 }
                 BFLog(1, message: "摄像录制小于1s")
             }
-        
+
         }
     }
     
-    override func cancelRecord(){
+    func dealCamera(_ isSuccess: Bool) {
         
-        revertLast()
-        BFLog(1, message: "摄像录制小于1s")
         
-        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {[weak self] in
-            guard let wself = self else { return }
-            
-            wself.updateUI(progress:  wself.currentAssetProgress)
-        }
     }
     
+
     override func deleteRecord(at: CMTime) {
         if let videoS = recordItem?.videoStickers.enumerated().first(where: { mod in
             CMTimeCompare(mod.1.timelineCMIn, at) <= 0 && CMTimeCompare(mod.1.timelineCMOut, at) > 0
@@ -338,21 +334,24 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             }
             
             item.materialDuraion = item.videoStickers.last?.timelineCMOut ?? .zero
-            BFLog(1, message: "删除时长:\(currDuration.seconds), currTime: \(currentAssetProgress.seconds), totl:\(item.materialDuraion.seconds)")
 
         }
+        changeRecordMaterail()
+        BFLog(1, message: "delete: video- \(recordItem?.videoStickers.count ?? 0), voice-\(recordItem?.voiceStickers.count ?? 0)")
     }
     
     // 录制失败 , 不足一秒时恢复上一次状态
     func revertLast(_ modIndex : Int = -1){
         hadDeleteVideoOfFailed = true
+
         var vmod : PQEditVisionTrackMaterialsModel?
         if modIndex >= 0 && modIndex < recordItem?.videoStickers.count ?? 0{
             vmod = recordItem?.videoStickers[modIndex]
-        }else{
-            vmod = recordItem?.videoStickers.first(where: { mod in
-                CMTimeCompare(mod.timelineCMIn, currentAssetProgress) >= 0
-            })
+        }else {
+//            vmod = recordItem?.videoStickers.first(where: { mod in
+//                CMTimeCompare(mod.timelineCMIn, currentAssetProgress) >= 0
+//            })
+            vmod = videoModel
         }
         if vmod != nil {
             vmod!.timelineCMOut = vmod!.timelineCMIn
@@ -361,6 +360,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             recordItem?.videoStickers.removeAll(where: { mod in
                 mod == vmod
             })
+            BFLog(1, message: "count videoStickers: \(recordItem?.videoStickers.count ?? 0)")
         }
         
         resetThumbImg()
@@ -378,8 +378,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
         recordItem?.thumbImgs = tmpThumbs
         DispatchQueue.main.async {[weak self] in
             guard let wself = self else { return }
-            
-            wself.cameraProgressV?.collectionV.reloadData()
+            wself.cameraProgressV?.resetThumIV()
         }
         
     }
@@ -551,18 +550,15 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             currentAssetProgress = .zero
             resetEnv()
         } else {
-            cameraProgressV?.collectionV.reloadData()
-            cameraProgressV?.collectionV.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
+            cameraProgressV?.resetThumIV()
+            cameraProgressV?.progressView.contentOffset = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
             progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
 
             cameraProgressV?.isHidden = false
             
             prepareToPlayNext(needPlay: false)
             avplayerReplaceItem(newItem: nil)
-            
-            if currentAssetProgress == .zero {
-                // 按钮为删除
-            }
+
         }
     }
     
@@ -588,7 +584,7 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
         progreddL?.text = CMTimeGetSeconds(currentAssetProgress).formatDurationToHMS()
 
         let p = CGPoint(x: currentAssetProgress.seconds * 70.0 / 5.0, y: 0)
-        cameraProgressV?.collectionV.contentOffset = p
+        cameraProgressV?.progressView.contentOffset = p
     }
     
     func updateUI(progress:CMTime){
@@ -605,7 +601,6 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
     // 添加新的缩略图
     func addNewThumb(){
         if let progressThumV = cameraProgressV {
-//            progressThumV.collectionV.reloadData()
             progressThumV.addThumbImages()
         }
     }
@@ -640,7 +635,7 @@ extension BFRecordScreenCameraManager : GPUImageVideoCameraDelegate {
                 guard let wself = self else { return }
                 
                 if img != nil {
-                    BFLog(1, message: "取一张缩略图出来 \(dur.seconds), \(wself.recordItem?.thumbImgs.count ?? 0)")
+//                    BFLog(1, message: "取一张缩略图出来 \(dur.seconds), \(wself.recordItem?.thumbImgs.count ?? 0)")
                     wself.recordItem?.thumbImgs.append(img!)
                     wself.videoModel.thumImgs?.append(img!)
                     wself.addNewThumb()

+ 15 - 14
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -76,11 +76,12 @@ public class BFRecordScreenController: BFBaseViewController {
                     (mod.timelineCMOut - mod.timelineCMIn).seconds + partialResult
                 })
                 wself.rscmanager.recordItem?.materialDuraion = CMTime(seconds: dur ?? 0, preferredTimescale: 1000)
-//                BFLog(1, message: "camera:\(sticker.timelineCMIn.seconds) ~ \(sticker.timelineCMOut.seconds)")
+                BFLog(1, message: "camera:\(sticker.timelineCMIn.seconds) ~ \(sticker.timelineCMOut.seconds)")
             }
         }
         return m
     }()
+    
     var rscurrentManager = BFRecordScreenBaseManager()
     
     // MARK: - 录制参数
@@ -854,13 +855,13 @@ public class BFRecordScreenController: BFBaseViewController {
                 newSubtitle.audioFilePath = currentVoice.wavFilePath
                 BFLog(3, message: "字幕回调-字幕返回begin:\(((payload?["begin_time"]) as? Int) ?? 0),timelineIn:\(newSubtitle.timelineIn.seconds), end:\(((payload?["time"]) as? Int) ?? 0),timelineOut:\(newSubtitle.timelineOut.seconds)")
                 if (newSubtitle.timelineIn - currentVoice.startCMTime).seconds > 0.1 {
-                    BFLog(1, message: "卡在录音尾巴上了1")
+//                    BFLog(1, message: "卡在录音尾巴上了1")
                     newSubtitle.timelineIn = newSubtitle.timelineIn - CMTime(seconds: 0.1, preferredTimescale: 1000)
                 }
                 let showText = ((payload?["result"]) as? String) ?? ""
                 newSubtitle.text = showText
 //                newSubtitle.audioFilePath = audioFilePath ?? ""
-                BFLog(1, message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn.seconds) timelineOut \(newSubtitle.timelineOut.seconds) text: \(newSubtitle.text)")
+//                BFLog(1, message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn.seconds) timelineOut \(newSubtitle.timelineOut.seconds) text: \(newSubtitle.text)")
                 newSubtitle.setting = wself.subtitleSettingView.subtitle.setting
                 tempItem?.titleStickers.append(newSubtitle)
             }
@@ -875,9 +876,12 @@ public class BFRecordScreenController: BFBaseViewController {
                 // 加入到语音数组里
 
                 model.endCMTime = wself.currentAssetProgress
-                BFLog(1, message: "录音地址:\((model.wavFilePath ?? "").replacingOccurrences(of: documensDirectory, with: ""))")
-                BFLog(1, message: "录音文件时长:\(model.startCMTime.seconds) -- \(model.endCMTime.seconds), dur: \(model.endCMTime.seconds - model.startCMTime.seconds)")
+//                BFLog(1, message: "录音地址:\((model.wavFilePath ?? "").replacingOccurrences(of: documensDirectory, with: ""))")
+                BFLog(1, message: "   文件时长record:\(wself.rscmanager.recordItem?.voiceStickers.count ?? 0),   \(model.startCMTime.seconds) -- \(model.endCMTime.seconds), dur: \(model.endCMTime.seconds - model.startCMTime.seconds)")
 
+                if model.endCMTime.seconds < model.startCMTime.seconds{
+                    BFLog(1, message: "error")
+                }
                 /// 注:录音机回调的录音时长大于一秒,而业务逻辑计算的会小于一秒
                 if (model.endCMTime.seconds - model.startCMTime.seconds) < 1 {
                     // 取消录制
@@ -1133,7 +1137,7 @@ public class BFRecordScreenController: BFBaseViewController {
             }
 
         case .ended:
-            BFLog(1, message: "移动结束 \(beginOnStartBtn)")
+//            BFLog(1, message: "移动结束 \(beginOnStartBtn)")
             if beginOnStartBtn == true {
                 beginOnStartBtn = false
                 endRecord()
@@ -1144,8 +1148,8 @@ public class BFRecordScreenController: BFBaseViewController {
                 //                }
             }
 
-        default:
-            BFLog(1, message: "pan default")
+        default: break
+//            BFLog(1, message: "pan default")
         }
     }
 
@@ -1211,8 +1215,6 @@ public class BFRecordScreenController: BFBaseViewController {
             events.append(event)
 
             rscurrentManager.deleteRecord(at: currentAssetProgress)
-
-            rscurrentManager.changeRecordMaterail()
             
             if currMediaType != .Video{
                 // 判断是否无录音了
@@ -1512,8 +1514,7 @@ public class BFRecordScreenController: BFBaseViewController {
                                 }
                                 DispatchQueue.main.async {[weak self] in
                                     guard let wself = self else { return }
-                                    
-                                    wself.rscmanager.cameraProgressV?.collectionV.reloadData()
+                                    wself.rscmanager.cameraProgressV?.resetThumIV()
                                 }
                             }
                         }
@@ -2024,7 +2025,7 @@ public class BFRecordScreenController: BFBaseViewController {
     }
 
     public func pause() {
-        BFLog(1, message: "暂停播放")
+//        BFLog(1, message: "暂停播放")
         isNormalPlaying = false
 
         subtitleBtn.isHidden = false
@@ -2614,7 +2615,7 @@ public extension BFRecordScreenController {
     /// 重绘录音进度视图
     func resetAllIndirectionView() {
         if currMediaType == .Camera {
-            rscmanager.cameraProgressV?.collectionV.reloadData()
+            rscmanager.cameraProgressV?.resetThumIV()
             rscmanager.prepareToPlayNext(needPlay: false)
             return
         }

+ 50 - 0
BFRecordScreenKit/Classes/RecordScreen/View/BFThumImageView.swift

@@ -0,0 +1,50 @@
+//
+//  BFThumImageView.swift
+//  BFRecordScreenKit
+//
+//  Created by 胡志强 on 2022/2/9.
+//
+
+import Foundation
+
+class BFThumImageView: UIImageView {
+    var isHiddenBord = false{
+        didSet{
+            if let v = self.viewWithTag(12333){
+                v.isHidden = isHiddenBord
+            }
+        }
+    }
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        addIndicationView()
+    }
+    
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    override init(image: UIImage?) {
+        super.init(image: image)
+        addIndicationView()
+    }
+    
+    func addIndicationView(){
+        let bottomView = UIView()
+        bottomView.backgroundColor = ThemeStyleColor
+        addSubview(bottomView)
+        bottomView.snp.makeConstraints { make in
+            make.left.bottom.width.equalToSuperview()
+            make.height.equalTo(6)
+        }
+        
+        let line = UIView()
+        line.backgroundColor = .black
+        line.tag = 12333
+        addSubview(line)
+        line.snp.makeConstraints { make in
+            make.right.top.bottom.equalToSuperview()
+            make.width.equalTo(1)
+        }
+    }
+}

+ 97 - 100
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFCameraProgressView.swift

@@ -13,38 +13,37 @@ import UIKit
 
 class BFCameraProgressView: BFProgressBaseView {
     
-    lazy var collectionV : UICollectionView = {
-        let flowLayout = UICollectionViewFlowLayout()
-        flowLayout.minimumLineSpacing = 0
-        flowLayout.minimumInteritemSpacing = 0
-        flowLayout.scrollDirection = .horizontal
-        flowLayout.itemSize = CGSize(width: self.frame.width, height: self.frame.height)
-        flowLayout.headerReferenceSize = CGSize(width: cScreenWidth / 2.0, height: 50)
-        flowLayout.footerReferenceSize = CGSize(width: cScreenWidth / 2.0, height: 50)
-
-        let cc = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height), collectionViewLayout: flowLayout)
-        cc.delegate = self
-        cc.dataSource = self
-        cc.bounces = false
-        cc.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier:  String(describing: UICollectionReusableView.self))
-        cc.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier:  String(describing: UICollectionReusableView.self))
-        cc.register(UICollectionViewCell.self, forCellWithReuseIdentifier: String(describing: UICollectionViewCell.self))
-        cc.showsVerticalScrollIndicator = false
-        cc.showsHorizontalScrollIndicator = false
-        cc.backgroundColor = UIColor.clear
-        cc.decelerationRate = .fast
-        
-        return cc
+    var imageViews = [BFThumImageView]()
+    
+    lazy var progressView: BFAutolayoutScrollView = {
+        let sv = BFAutolayoutScrollView()
+        sv.bounces = false
+//        sv.backgroundColor = .clear
+//        sv.backgroundColor = UIColor.hexColor(hexadecimal: "#888888",alpha:0.3)
+        sv.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
+        sv.decelerationRate = .fast
+        sv.showsHorizontalScrollIndicator = false
+        sv.delegate = self
+        return sv
     }()
     
     override init(frame: CGRect) {
         super.init(frame: frame)
 
-        addSubview(collectionV)
-        insertSubview(collectionV, belowSubview: line)
+//        addSubview(collectionV)
+//        insertSubview(collectionV, belowSubview: line)
         
+        insertSubview(progressView, belowSubview: line)
     }
 
+    override func layoutSubviews() {
+        super.layoutSubviews()
+
+        progressView.snp.makeConstraints { make in
+            make.edges.equalToSuperview()
+        }
+    }
+    
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
@@ -52,100 +51,98 @@ class BFCameraProgressView: BFProgressBaseView {
     /// 添加缩略图
     /// - Parameter images:
     func addThumbImages() {
-        if let count = recordItem?.thumbImgs.count, count > 0 {
-            DispatchQueue.main.async {[weak self] in
-                guard let wself = self else { return }
-                //mdf by ak reloadData 这个方法,在录制5S 前进度不会走。
-                wself.collectionV.reloadData()
-//                wself.collectionV.insertItems(at: [IndexPath(row: count - 1, section: 0)])
-            }
-        }
-    }
-    
-    func updateCellWidth(index:Int, progress:CMTime){
-        if let count = recordItem?.thumbImgs.count, count > 0, collectionV.cellForItem(at: IndexPath(row: count - 1, section: 0)) != nil {
+        DispatchQueue.main.async {[weak self] in
+            guard let wself = self else { return }
             
-            let p = CGPoint(x: progress.seconds * 70 / 5.0, y: 0)
-            if p.x - collectionV.contentOffset.x > (1.0 / UIScreen.main.scale) {
-                UIView.performWithoutAnimation {
-                    collectionV.reloadItems(at: [IndexPath(row: count - 1, section: 0)])
+            if let img = wself.recordItem?.thumbImgs.last {
+                let iv = BFThumImageView(image: img)
+                iv.image = img
+                iv.contentMode = .scaleAspectFill
+                iv.clipsToBounds = true
+                iv.isHiddenBord = true
+                wself.progressView.contentView.addSubview(iv)
+
+                if let lastiv = wself.imageViews.last {
+                    iv.frame = CGRect(x: lastiv.rightX, y: lastiv.y, width: 0, height: 50)
+                    lastiv.isHiddenBord = false
+                }else{
+                    iv.frame = CGRect(x: cScreenWidth / 2.0, y: 0, width: 0, height: 50)
                 }
-                collectionV.contentOffset = p
+                wself.imageViews.append(iv)
+                BFLog(1, message: "\(wself.imageViews.count), if frame : \(iv.frame)")
+                wself.progressView.setNeedsLayout()
+                wself.progressView.layoutIfNeeded()
             }
+            
         }
-    }
-}
-
-extension BFCameraProgressView: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
-    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return recordItem?.thumbImgs.count ?? 0
+        
     }
     
-    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
-        if kind == UICollectionView.elementKindSectionHeader || kind == UICollectionView.elementKindSectionFooter{
-            let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: UICollectionReusableView.self), for: indexPath)
-            header.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
-            return header
+    func resetThumIV() {
+        imageViews.forEach { iv in
+            iv.removeFromSuperview()
         }
-        return UICollectionReusableView()
-    }
-    
-    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-        var size : CGSize = .zero
-        if let img = recordItem?.thumbImgs[indexPath.row] {
-            if let sticker = recordItem?.videoStickers.first(where: { m in
-                m.thumImgs?.contains(img) ?? false
-            }) {
-                if let (ind, _) = sticker.thumImgs?.enumerated().first(where: { ele in
-                    ele.1 == img
-                }) {
-                    let wid = ((sticker.timelineCMOut - sticker.timelineCMIn).seconds / 5.0  -  CGFloat(ind))*70.0
-//                    let wid0 = floor(wid0 * UIScreen.main.scale) /  UIScreen.main.scale
-//                    size = CGSize(width: max(1.0 / UIScreen.main.scale, min(wid0, 70.0)), height: 50.0)
-                    size = CGSize(width: max(1.0 / UIScreen.main.scale, min(wid, 70.0)), height: 50.0)
-
-//                    BFLog(1, message: "size \(indexPath.row):\(wid0) - \(wid)")
-                }
-                
-                if size.width < 0 {
-                    BFLog(1, message: "ewrr")
-                    size = .zero
+        imageViews.removeAll()
+        
+        var leftah:CGFloat = cScreenWidth / 2
+        if let vstickers = recordItem?.videoStickers {
+            for sticker in vstickers {
+                if let thumimgs = sticker.thumImgs{
+                    for (ind, img) in thumimgs.enumerated(){
+                        let iv = BFThumImageView(image: img)
+                        iv.image = img
+                        iv.contentMode = .scaleAspectFill
+                        iv.clipsToBounds = true
+                        iv.isHiddenBord = false
+                        progressView.contentView.addSubview(iv)
+                        imageViews.append(iv)
+                        
+                        // 计算iv的宽和偏移量
+                        let wid = (sticker.timelineCMOut - sticker.timelineCMIn).seconds.truncatingRemainder(dividingBy: 5.0)  * 70.0 / 5.0
+                        let wid0 = (ind < (thumimgs.count - 1)) ? 70 : floor(wid * UIScreen.main.scale) /  UIScreen.main.scale
+                        let x = CGFloat(ind) * 70.0
+                        iv.frame = CGRect(x: leftah + x, y: 0.0, width: wid0, height: 50.0)
+                    }
+                    leftah = imageViews.last?.rightX ?? 0.0
                 }
-
-//                BFLog(1, message: "curr size - row:\(indexPath.row), \(size.width)")
             }
         }
-//        BFLog(1, message: "size:\(size.width)")
+        
+        if let lastiv = imageViews.last {
+            lastiv.isHiddenBord = true
+        }
+        
+        let p = CGPoint(x: leftah - cScreenWidth / 2.0, y: 0)
 
-        return size
+        progressView.contentOffset = p
+        progressView.contentSize = CGSize(width: p.x + cScreenWidth, height: 50)
     }
     
-    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: UICollectionViewCell.self), for: indexPath)
-        cell.contentView.clipsToBounds = true
-        var imgview : UIImageView? = cell.contentView.viewWithTag(13000) as? UIImageView
-        if  imgview == nil {
-            imgview = UIImageView(frame: CGRect(x: 0, y: 0, width: 70, height: 50))
-            imgview?.contentMode = .scaleAspectFill
-            imgview?.tag = 13000
-            cell.contentView.addSubview(imgview!)
-            
-            let line = UIView()
-            line.backgroundColor = ThemeStyleColor
-            line.frame = CGRect(x: 0, y: 44, width: 70, height: 6)
-            cell.contentView.addSubview(line)
+    func updateCellWidth(index:Int, progress:CMTime) {
+        if let sticker = recordItem?.videoStickers.first(where: { mod in
+            CMTimeCompare(mod.timelineCMIn, progress) <= 0 &&  CMTimeCompare(mod.timelineCMOut, progress) >= 0
+        }) {
+            let wid = (sticker.timelineCMOut - sticker.timelineCMIn).seconds.truncatingRemainder(dividingBy: 5.0)  * 70.0 / 5.0
+            let wid0 = floor(wid * UIScreen.main.scale) /  UIScreen.main.scale
+            if index < imageViews.count{
+                let lastiv = imageViews[index]
+                if wid0 <= lastiv.width {
+                    return
+                }
+                var frame = lastiv.frame
+                frame.size.width = wid0
+                lastiv.frame = frame
+            }
 
+            let p = CGPoint(x: progress.seconds * 70 / 5.0, y: 0)
+            progressView.contentOffset = p
+            progressView.contentSize = CGSize(width: p.x + cScreenWidth, height: 50)
+//            BFLog(1, message: "contentSize: \(progressView.contentSize)")
         }
-        if indexPath.row < recordItem?.thumbImgs.count ?? 0{
-            imgview?.image = recordItem?.thumbImgs[indexPath.row]
-        }
-        
-//        BFLog(1, message: "cell manke: \(indexPath.row)")
-        return cell
     }
 }
 
-extension BFCameraProgressView {
+extension BFCameraProgressView: UIScrollViewDelegate {
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
         if isDrag {
             dragScrollProgressHandle?(false, scorllToProgress(scrollView))

+ 1 - 0
_Pods.xcodeproj

@@ -0,0 +1 @@
+Example/Pods/Pods.xcodeproj