소스 검색

撤销行为素材内记录

harry 3 년 전
부모
커밋
1dddc86a46

+ 3 - 0
BFRecordScreenKit/Classes/BFRecordItemModel.swift

@@ -28,6 +28,9 @@ public class BFRecordItemModel: NSObject {
     public var videoStickers = [PQEditVisionTrackMaterialsModel]() // 合成导出时计算
     public var imageStickers = [PQEditVisionTrackMaterialsModel]() //
     public var titleStickers = [PQEditSubTitleModel]() // 字幕贴纸
+    
+    var events = [WithDrawModel]() // 行为记录,方便撤销
+
     public var coverImg: UIImage? // 封面图
     public var thumbImgs = [UIImage]() // 缩略图集合
     public var playItem: AVPlayerItem? // 视频playerItem

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

@@ -113,9 +113,8 @@ public class BFRecordScreenController: BFBaseViewController {
                     return CMTimeRangeGetIntersection(originRange, otherRange: newRange).duration.seconds > 0
                 }
                 BFLog(1, message: "添加录音文件:\(model.startTime) -- \(model.endTime)")
-                sself.withDrawBtn.setTitle("撤销录制", for: .normal)
                 DispatchQueue.main.async {[weak self] in
-                    self?.changeWithDrawBtnLayout()
+                    self?.changeWithDrawBtnLayout(true)
                 }
                 var event = sself.events.last
                 if event != nil {
@@ -875,11 +874,9 @@ public class BFRecordScreenController: BFBaseViewController {
             }
 
             if let event = events.last, event.type == 2 {
-                withDrawBtn.setTitle("撤销录制", for: .normal)
-                changeWithDrawBtnLayout()
+                changeWithDrawBtnLayout(true)
             } else {
-                withDrawBtn.setTitle("撤销", for: .normal)
-                changeWithDrawBtnLayout()
+                changeWithDrawBtnLayout(false)
             }
             searchStopAtRecordRange()
         }
@@ -896,7 +893,7 @@ public class BFRecordScreenController: BFBaseViewController {
             searchStopAtRecordRange()
         } else {
             events.append(WithDrawModel(type: 1, timestamp: currentAssetProgress.seconds))
-            withDrawBtn.setTitle("撤销", for: .normal)
+            changeWithDrawBtnLayout(false)
             play()
         }
     }
@@ -924,7 +921,7 @@ public class BFRecordScreenController: BFBaseViewController {
         hadPrepareToPlayRecord = false
         BFLog(1, message: isDragingProgressSlder ? "drag false" : "drag  tr")
         searchStopAtRecordRange()
-        withDrawBtn.setTitle("撤销", for: .normal)
+        changeWithDrawBtnLayout(false)
     }
 
     func searchStopAtRecordRange() {
@@ -1267,7 +1264,12 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: - 录音对应图像绘制
     
     // 撤销按钮修改title,重绘
-    func changeWithDrawBtnLayout() {
+    func changeWithDrawBtnLayout(_ recorded:Bool) {
+        if recorded {
+            withDrawBtn.setTitle("撤销录制", for: .normal)
+        }else {
+            withDrawBtn.setTitle("撤销", for: .normal)
+        }
         withDrawBtn.imageEdgeInsets = UIEdgeInsets(top: -withDrawBtn.imageView!.height, left: 0, bottom: 0, right: -withDrawBtn.titleLabel!.width)
         withDrawBtn.titleEdgeInsets = UIEdgeInsets(top: withDrawBtn.titleLabel!.height + 2, left: -withDrawBtn.imageView!.width, bottom: 0, right: 0)
         
@@ -1421,23 +1423,28 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             // 暂停状态
             let lastCell: BFImageCoverViewCell? = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
             lastCell?.playBtn.isSelected = false
-            // 更新当前page
-            currItemModelIndex = page
-            let recordItem = itemModels[currItemModelIndex]
+            
+            let recordItem = itemModels[page]
             // 重绘录音区域
             drawOrUpdateRecordProgessLable()
             // 更新缩略图
             progressThumV.recordItem = recordItem
             progressThumV.isHidden = false
             if recordItem.mediaType == .VIDEO {
-                let currCell: BFImageCoverViewCell? = collectionView.cellForItem(at: IndexPath(item: currItemModelIndex, section: 0)) as? BFImageCoverViewCell
+                let currCell: BFImageCoverViewCell? = collectionView.cellForItem(at: IndexPath(item: page, section: 0)) as? BFImageCoverViewCell
                 setVideoPlay(item: recordItem.playItem, imageView: currCell?.playView)
                 setAudioPlay(item: recordItem.playItem)
                 assetPlayer?.seek(to: .zero, toleranceBefore: CMTime(value: 1, timescale: 1000), toleranceAfter: CMTime(value: 1, timescale: 1000))
             }
             if changeItemHandle != nil {
-                changeItemHandle!(currItemModelIndex)
+                changeItemHandle!(page)
             }
+            // 重设撤销栈
+            itemModels[currItemModelIndex].events = events
+            events = itemModels[page].events
+            
+            // 更新当前page
+            currItemModelIndex = page
         }
     }