Browse Source

修改摄像头缩略图延迟问题;
fix:整个录音分割线显示,不是图片
优化分割线显示逻辑

胡志强 3 years ago
parent
commit
0084cc4f6e

+ 4 - 0
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenCameraManager.swift

@@ -242,6 +242,10 @@ class BFRecordScreenCameraManager : BFRecordScreenBaseManager{
             if cameraSuccess {
                 wself.currentAssetProgress = wself.videoModel.timelineCMOut
                 wself.recordEndCallBack?(true, wself.videoModel)
+                wself.updateUI(progress: wself.currentAssetProgress)
+                if let img = wself.videoModel.thumImgs?.last{
+                    wself.cameraProgressV?.changeSepline(img: img)
+                }
             }else {
                 wself.videoModel.locationPath = "nil"
                 wself.revertLast()

+ 3 - 3
BFRecordScreenKit/Classes/RecordScreen/View/BFIndirectionProgressView.swift

@@ -105,7 +105,7 @@ class BFIndirectionProgressView: UIView {
     ///   - start: <#start description#>
     ///   - progress: <#progress description#>
     /// - Returns: <#description#>
-    func detectionItem(start: CGFloat = 0, progress: Float64) -> UIView {
+    func detectionItem(start: CGFloat = 0, progress: Float64) -> BFThumImageView? {
         let newRange = CMTimeRange(start: CMTime(seconds: start, preferredTimescale: 1000), end: CMTime(seconds: start + progress, preferredTimescale: 1000))
         var currentIndex: Int?
         for (index, item) in subviews.enumerated() {
@@ -117,7 +117,7 @@ class BFIndirectionProgressView: UIView {
         }
         if currentIndex != nil {
             BFLog(message: "检测存在重新创建")
-            return subviews[currentIndex!]
+            return subviews[currentIndex!] as? BFThumImageView
         } else {
             BFLog(message: "检测不存在重新创建:\(start)")
             return createItemView(minX: start * percenWidth)
@@ -157,7 +157,7 @@ class BFIndirectionProgressView: UIView {
     ///   - width: <#width description#>
     ///   - indirec: <#indirec description#>
     /// - Returns: <#description#>
-    func createItemView(minX: CGFloat, width: CGFloat = 0, indirec: Bool = false) -> UIView {
+    func createItemView(minX: CGFloat, width: CGFloat = 0, indirec: Bool = false) -> BFThumImageView {
         var newW = width
         if width.isNaN || width.isInfinite {
             newW = 0

+ 5 - 3
BFRecordScreenKit/Classes/RecordScreen/View/BFThumImageView.swift

@@ -6,6 +6,7 @@
 //
 
 import Foundation
+import UIKit
 
 class BFThumImageView: UIView {
     var isHiddenBord = false{
@@ -18,7 +19,8 @@ class BFThumImageView: UIView {
     
     fileprivate let iv : UIImageView = {
         let iv = UIImageView()
-        iv.frame = CGRect(x: 0, y: 0, width: 79, height: 50)
+        iv.frame = CGRect(x: 0, y: 0, width: 70, height: 50)
+        iv.contentMode = .scaleAspectFill
         return iv
     }()
     
@@ -60,12 +62,12 @@ class BFThumImageView: UIView {
         }
         
         let line = UIView()
-        line.backgroundColor = .black
+        line.backgroundColor = UIColor.init(white: 0, alpha: 0.5)
         line.tag = 12333
         addSubview(line)
         line.snp.makeConstraints { make in
             make.right.top.bottom.equalToSuperview()
-            make.width.equalTo(1)
+            make.width.equalTo(1.5)
         }
     }
 }

+ 24 - 12
BFRecordScreenKit/Classes/RecordScreen/View/ProgressView/BFCameraProgressView.swift

@@ -15,6 +15,8 @@ class BFCameraProgressView: BFProgressBaseView {
     
     var imageViews = [BFThumImageView]()
     
+    var newRecord = false
+    
     lazy var progressView: BFAutolayoutScrollView = {
         let sv = BFAutolayoutScrollView()
         sv.bounces = false
@@ -64,12 +66,16 @@ class BFCameraProgressView: BFProgressBaseView {
 
                 if let lastiv = wself.imageViews.last {
                     iv.frame = CGRect(x: lastiv.rightX, y: lastiv.y, width: 0, height: 50)
-                    lastiv.isHiddenBord = false
+                    if wself.newRecord {
+                        lastiv.isHiddenBord = false
+                        wself.newRecord = false
+                    }
+                    BFLog(1, message: "frame: \(lastiv.viewWithTag(12333)!.convert(lastiv.viewWithTag(12333)!.bounds     , to: wself.progressView.contentView)), \(iv.frame)")
                 }else{
                     iv.frame = CGRect(x: cScreenWidth / 2.0, y: 0, width: 0, height: 50)
                 }
                 wself.imageViews.append(iv)
-                BFLog(1, message: "\(wself.imageViews.count), if frame : \(iv.frame)")
+
                 wself.progressView.setNeedsLayout()
                 wself.progressView.layoutIfNeeded()
             }
@@ -93,17 +99,18 @@ class BFCameraProgressView: BFProgressBaseView {
                         iv.image = img
                         iv.contentMode = .scaleAspectFill
                         iv.clipsToBounds = true
-                        iv.isHiddenBord = false
+                        iv.isHiddenBord = true
                         progressView.contentView.addSubview(iv)
                         imageViews.append(iv)
                         
                         // 计算iv的宽和偏移量
-                        let wid = (sticker.timelineCMOut - sticker.timelineCMIn).seconds.truncatingRemainder(dividingBy: 5.0)  * 70.0 / 5.0
+                        let wid = sticker.timelineCMOut.seconds * 70.0 / 5.0 - (leftah - cScreenWidth / 2.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)
+//                        let x = (sticker.timelineCMIn.seconds + Double(ind) * 5.0) * 70.0 / 5.0
+                        iv.frame = CGRect(x: leftah, y: 0.0, width: wid0, height: 50.0)
+                        leftah = iv.rightX
                     }
-                    leftah = imageViews.last?.rightX ?? 0.0
+                    (progressView.contentView.subviews.last as? BFThumImageView)?.isHiddenBord = false
                 }
             }
         }
@@ -112,7 +119,7 @@ class BFCameraProgressView: BFProgressBaseView {
             lastiv.isHiddenBord = true
         }
         
-        let p = CGPoint(x: leftah - cScreenWidth / 2.0, y: 0)
+        let p = CGPoint(x: (imageViews.last?.rightX ?? 0.0) - cScreenWidth / 2.0, y: 0)
 
         progressView.contentOffset = p
         progressView.contentSize = CGSize(width: p.x + cScreenWidth, height: 50)
@@ -122,11 +129,12 @@ class BFCameraProgressView: BFProgressBaseView {
         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 {
+                let wid = progress.seconds * 70.0 / 5.0 - (lastiv.x - cScreenWidth / 2.0)
+                let wid0 = floor(wid * UIScreen.main.scale) /  UIScreen.main.scale
+                
+                if wid0 <= lastiv.width || wid0 > 70{
                     return
                 }
                 var frame = lastiv.frame
@@ -137,9 +145,13 @@ class BFCameraProgressView: BFProgressBaseView {
             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)")
+            BFLog(1, message: "contentSize: \(progressView.contentSize)")
         }
     }
+    
+    func changeSepline(img:UIImage){
+        newRecord = true
+    }
 }
 
 extension BFCameraProgressView: UIScrollViewDelegate {