harry 3 år sedan
förälder
incheckning
d78b568efb

+ 9 - 7
BFRecordScreenKit/Classes/RecordScreen/Controller/BFMusicSearchController.swift

@@ -121,7 +121,7 @@ class BFMusicSearchController: BFBaseViewController {
         view.addSubview(musicTb)
         musicTb.snp.makeConstraints { make in
             make.left.right.equalToSuperview()
-            make.top.equalTo(searchTF.snp.bottom).offset(4)
+            make.top.equalTo(statusBarHeight + 44)
             make.bottom.equalTo(-100)
         }
         
@@ -148,13 +148,15 @@ class BFMusicSearchController: BFBaseViewController {
                 guard let wself = self else { return }
                 
                 guard let ranges = change.newValue as? [CMTimeRange] else { return }
-                if let indx = wself.chosedIndexPath, let cell = wself.musicTb.cellForRow(at: indx) as? BFMuicInfoCell, let totalDur = player.currentItem?.duration, totalDur.isValid,  CMTimeCompare(ranges.first?.duration ?? .zero, totalDur) >= 0{
-                    if (player.currentItem?.asset as? AVURLAsset)?.url.absoluteString ?? "b" == cell.data?.musicPath ?? "a" {
-                        if cell.status == .loading{
-                            cell.status = .playing
-                            wself.chosedCellStatu = .playing
+                if let totalDur = player.currentItem?.duration, totalDur.isValid,  CMTimeCompare(ranges.first?.duration ?? .zero, totalDur) >= 0{
+                    if let indx = wself.chosedIndexPath, let cell = wself.musicTb.cellForRow(at: indx) as? BFMuicInfoCell {
+                        if (player.currentItem?.asset as? AVURLAsset)?.url.absoluteString ?? "b" == cell.data?.musicPath ?? "a" {
+                            if cell.status == .loading{
+                                cell.status = .playing
+                            }
                         }
                     }
+                    wself.chosedCellStatu = .playing
                 }
 //                BFLog(1, message: "开始播放音乐:\(ranges.first?.start.seconds ?? 0), dur:\( ranges.first?.duration.seconds ?? 0), tot:\(player.currentItem?.duration.seconds ?? 0)")
             }
@@ -292,6 +294,7 @@ extension BFMusicSearchController : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
+        searchResults[indexPath.row].isSelected = false
         let cell = tableView.cellForRow(at: indexPath) as? BFMusicInfoSearchCell
         cell?.status = .normal
         cell?.changeSelected(false)
@@ -314,7 +317,6 @@ extension BFMusicSearchController : UITableViewDelegate, UITableViewDataSource {
                 var bgmList = [PQVoiceModel]()
                 if response is NSNull || response == nil {
                     DispatchQueue.main.async {
-
                         cShowHUB(superView: nil, msg: "网络连接失败,请检查网络后重试")
                     }
                     return

+ 1 - 0
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -1589,6 +1589,7 @@ public class BFRecordScreenController: BFBaseViewController {
             
             wself.choseMusicPanel.frame = CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth)
         }
+        choseMusicPanel.refreshCurrSelectModel(mod: bgmModel)
     }
 
     /// 删除指定段落的所有字幕 数据

+ 11 - 1
BFRecordScreenKit/Classes/RecordScreen/View/BFChooseMusicView.swift

@@ -404,12 +404,20 @@ class BFChooseMusicView: UIView {
     
     // 取消选歌
     func cancelChooseMusic() {
-        chosedMusic = nil
+//        chosedMusic = nil
         player.pause()
         choseCell()?.status = .normal
         choseCell()?.changeSelected(false)
         chosedIndexPath = nil
     }
+    
+    
+    func refreshCurrSelectModel(mod:PQVoiceModel?) {
+        if let mod = mod {
+            mod.isSelected = true
+        }
+        musicTb.reloadData()
+    }
 }
 
 extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
@@ -500,7 +508,9 @@ extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
+        
         let cell = tableView.cellForRow(at: indexPath) as? BFMuicInfoCell
+        
         cell?.status = .normal
         cell?.changeSelected(false)
         

+ 55 - 17
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFMuicInfoCell.swift

@@ -16,7 +16,8 @@ enum BFMuicInfoCellState {
 
 class BFMuicInfoCell: UITableViewCell {
     var cutCallBack : (() -> Void)?
-    
+    var useCallback : (() -> Void)?
+
     var data:PQVoiceModel?{
         didSet{
             addData()
@@ -87,6 +88,25 @@ class BFMuicInfoCell: UITableViewCell {
         return l
     }()
     
+    lazy var cutBtn : UIButton = {
+        let cutBtn = UIButton()
+        cutBtn.tag = 2001
+        cutBtn.setImage(imageInRecordScreenKit(by: "clip"), for: .normal)
+        cutBtn.addTarget(self, action: #selector(cutAction), for: .touchUpInside)
+        return cutBtn
+    }()
+    
+    lazy var useBtn : UIButton = {
+        let useBtn = UIButton()
+        useBtn.tag = 2002
+        useBtn.setTitle("使用", for: .normal)
+        useBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#389AFF")
+        useBtn.layer.cornerRadius = 4
+        useBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
+        useBtn.addTarget(self, action: #selector(useBtnAction), for: .touchUpInside)
+        return useBtn
+    }()
+    
     override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
         super.init(style: style, reuseIdentifier: reuseIdentifier)
         self.backgroundColor = .clear
@@ -100,8 +120,32 @@ class BFMuicInfoCell: UITableViewCell {
         iconIV.addSubview(audioStateView)
         contentView.addSubview(iconIV)
         
+
         titleL.frame = CGRect(x: iconIV.rightX + 10, y: 12, width: width - iconIV.rightX - 10 - 90, height: 40)
+        contentView.addSubview(useBtn)
+        useBtn.snp.makeConstraints { make in
+            make.right.equalTo(-16)
+            make.width.equalTo(0)
+            make.height.equalTo(40)
+            make.top.equalTo(12)
+        }
+                
+        contentView.addSubview(cutBtn)
+        cutBtn.snp.makeConstraints { make in
+            make.right.equalTo(useBtn.snp.left).offset(-2)
+            make.width.equalTo(0)
+            make.height.equalTo(40)
+            make.top.equalTo(12)
+        }
+        
         contentView.addSubview(titleL)
+        titleL.snp.makeConstraints { make in
+            make.left.equalTo(iconIV.snp.right).offset(10)
+            make.top.equalTo(12)
+            make.height.equalTo(40)
+            make.right.equalTo(cutBtn.snp.left).offset(-2)
+        }
+        
 
     }
     
@@ -134,28 +178,17 @@ class BFMuicInfoCell: UITableViewCell {
             titleL.font = UIFont.systemFont(ofSize: 16, weight: .regular)
         }
     }
-    
-    func createCutBtn() -> UIButton {
-        let cutBtn = UIButton()
-        cutBtn.tag = 2001
-        cutBtn.setImage(imageInRecordScreenKit(by: "clip"), for: .normal)
-        cutBtn.addTarget(self, action: #selector(cutAction), for: .touchUpInside)
-        return cutBtn
-    }
+
     
     func showFunctionBtn() {
-        let cutBtn = createCutBtn()
-        contentView.addSubview(cutBtn)
-        cutBtn.snp.makeConstraints { make in
-            make.right.equalTo(-18)
-            make.width.height.equalTo(40)
-            make.top.equalTo(12)
+        cutBtn.snp.updateConstraints { make in
+            make.width.equalTo(40)
         }
     }
     
     func hiddenFunctionBtn() {
-        if let v = contentView.viewWithTag(2001) {
-            v.removeFromSuperview()
+        cutBtn.snp.updateConstraints { make in
+            make.width.equalTo(0)
         }
     }
     
@@ -163,6 +196,11 @@ class BFMuicInfoCell: UITableViewCell {
         cutCallBack?()
     }
     
+    
+    @objc func useBtnAction() {
+        useCallback?()
+    }
+    
     func loadingAnimation(){
         let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
         // 2.设置动画的属性

+ 10 - 33
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFMusicInfoSearchCell.swift

@@ -10,47 +10,24 @@ import Foundation
 
 class BFMusicInfoSearchCell: BFMuicInfoCell {
     
-    var useCallback : (() -> Void)?
     
     override func showFunctionBtn() {
-        
-        let useBtn = createUseBtn()
-        contentView.addSubview(useBtn)
-        useBtn.snp.makeConstraints { make in
-            make.right.equalTo(-18)
-            make.width.equalTo(46)
-            make.top.equalTo(18)
-            make.bottom.equalTo(-18)
+        cutBtn.snp.updateConstraints { make in
+            make.width.equalTo(40)
         }
-        
-        let cutBtn = createCutBtn()
-        contentView.addSubview(cutBtn)
-        cutBtn.snp.makeConstraints { make in
-            make.right.equalTo(useBtn.snp.left).offset(-4)
-            make.width.height.equalTo(40)
-            make.top.equalTo(12)
+        useBtn.snp.updateConstraints { make in
+            make.width.equalTo(40)
         }
+        
     }
     
     override func hiddenFunctionBtn() {
-        super.hiddenFunctionBtn()
-        if let v = contentView.viewWithTag(2002){
-            v.removeFromSuperview()
+        cutBtn.snp.updateConstraints { make in
+            make.width.equalTo(0)
+        }
+        useBtn.snp.updateConstraints { make in
+            make.width.equalTo(0)
         }
     }
     
-    func createUseBtn() -> UIButton {
-        let useBtn = UIButton()
-        useBtn.tag = 2002
-        useBtn.setTitle("使用", for: .normal)
-        useBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#389AFF")
-        useBtn.layer.cornerRadius = 4
-        useBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
-        useBtn.addTarget(self, action: #selector(useBtnAction), for: .touchUpInside)
-        return useBtn
-    }
-    
-    @objc func useBtnAction() {
-        useCallback?()
-    }
 }