Selaa lähdekoodia

1,更换节奏位置

jsonwang 3 vuotta sitten
vanhempi
commit
647ac53151

+ 2 - 2
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -99,7 +99,7 @@ class PQStuckPointEditerController: PQBaseViewController {
 
     /// 节奏选择视图
     lazy var sustomSwitchView: PQCustomSwitchView = {
-        let sustomSwitchView = PQCustomSwitchView(frame: CGRect(x: 16, y: 0, width: 180, height: 30), titles: ["快节奏", "适中", "慢节奏"], defaultIndex: stuckPointMusicData?.speed ?? 2)
+        let sustomSwitchView = PQCustomSwitchView(frame: CGRect(x: 16, y: 0, width: 180, height: 30), titles: ["慢节奏", "适中", "快节奏"], defaultIndex: stuckPointMusicData?.speed ?? 2)
         sustomSwitchView.switchChangeHandle = { [weak self] sender in
             // 改变速率,.只有快慢速且非只有图片素材时自动+1处理
             self?.stuckPointMusicData?.speed = sender.tag
@@ -469,7 +469,7 @@ class PQStuckPointEditerController: PQBaseViewController {
         }
         
         //更新一下节奏的 UI
-        sustomSwitchView.selectOneBtn(Index: (stuckPointMusicData?.speed ?? 2) - 1)
+        sustomSwitchView.selectOneBtn(Index: (stuckPointMusicData?.speed ?? 2))
     }
 
     // 点击搜索音乐

+ 19 - 7
BFFramework/Classes/Stuckpoint/View/PQCustomSwitchView.swift

@@ -14,7 +14,7 @@ class PQCustomSwitchView: UIView {
     /// 按钮点击的回调
     var switchChangeHandle: ((_ sender: UIButton) -> Void)?
  
-    var saveBtn:Array<UIButton> = Array.init()
+    var saveBtns:Array<UIButton> = Array.init()
     
     override private init(frame: CGRect) {
         super.init(frame: frame)
@@ -24,6 +24,14 @@ class PQCustomSwitchView: UIView {
         fatalError("init(coder:) has not been implemented")
     }
 
+    /*
+     服务器返回的 (1:快节奏,2:适中,3:慢节奏) ,
+     一,快慢速模式下取卡点 2 3 4
+     二,跳跃卡点模式下根据不同速度 取卡点 1,2,3
+     快节奏为选中区域的所有点位,即0,1,2,3,4 5 6 7 8 9 10 ……
+     适中为每两个点位取一个,即0,2,4,6……
+     慢节奏为每三个点位取一个,即0,3,6,9……
+     */
     init(frame: CGRect, titles: [String], defaultIndex: Int = 1) {
         super.init(frame: frame)
         BFLog(message: "初始时选择的位置 is \(defaultIndex)")
@@ -32,14 +40,13 @@ class PQCustomSwitchView: UIView {
             let itemBtn = UIButton(type: .custom)
             //8 是每一个btn 的间隔
             itemBtn.frame = CGRect(x: CGFloat(index) * itemWidth + CGFloat(index) * 8, y: 0, width: itemWidth, height: frame.height)
-            itemBtn.tag = index + 1
+            itemBtn.tag = (3 - index)
             itemBtn.setTitle(itemTitle, for: .normal)
             itemBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#959595"), for: .normal)
             itemBtn.setTitleColor(UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue), for: .selected)
             itemBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
   
-            itemBtn.isSelected = index == (defaultIndex - 1)
-            if index == (defaultIndex - 1) {
+            if itemBtn.tag == defaultIndex  {
                 itemBtn.isSelected = true
               
                 currentItemBtn = itemBtn
@@ -54,13 +61,18 @@ class PQCustomSwitchView: UIView {
             itemBtn.addCorner(corner:5)
             addSubview(itemBtn)
             
-            saveBtn.append(itemBtn)
+            saveBtns.append(itemBtn)
         }
     }
     
     func selectOneBtn(Index:Int) {
-         BFLog(message: "选择节奏 \(Index)")
-          updateSelectBtn(sender: saveBtn[Index])
+         
+        let selectIndex = saveBtns.firstIndex(where: { (svaeBtn) -> Bool in
+
+            (svaeBtn.tag == Index)
+        })
+        BFLog(message: "选择节奏 \(selectIndex ?? -1)")
+        updateSelectBtn(sender: saveBtns[selectIndex ?? 0])
     }
     
     func updateSelectBtn(sender: UIButton) {