|  | @@ -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))
 |