瀏覽代碼

偶现波纹没有画上去的问题

huzhiqiang 3 年之前
父節點
當前提交
3161f08db3
共有 1 個文件被更改,包括 9 次插入4 次删除
  1. 9 4
      BFFramework/Classes/Stuckpoint/View/PQStuckPointCuttingView.swift

+ 9 - 4
BFFramework/Classes/Stuckpoint/View/PQStuckPointCuttingView.swift

@@ -61,6 +61,7 @@ class PQStuckPointCuttingView: UIView {
 
     // 保存已经绘制的竖线用于变色使用
     var lineLayerArray: Array = Array<CAShapeLayer>.init()
+    var lastDrawedLineIndex : Int = 0
 
     // 裁剪区的相素大小
     var cropViewWidth: CGFloat = adapterWidth(width: 250)
@@ -296,15 +297,18 @@ class PQStuckPointCuttingView: UIView {
         }
         
         let startIndex = scrollView.contentOffset.x / (frequencyWidth + frequencyMargin)
+        lastDrawedLineIndex = max(lastDrawedLineIndex, Int(ceil(startIndex)))
         let selectIndex = Int(ceil(startIndex + progress * CGFloat(wavSelectCount)))
-        if(selectIndex < lineLayerArray.count){
-            let drawLayer:CAShapeLayer = lineLayerArray[selectIndex]
-//            BFLog(1, message: "progress is \(progress) i \(selectIndex) 命中的位置:\(CGFloat(selectIndex) * oneMarginTime)")
+        while(selectIndex < lineLayerArray.count && selectIndex > lastDrawedLineIndex){
+            let drawLayer:CAShapeLayer = lineLayerArray[lastDrawedLineIndex]
             if drawLayer.strokeColor != UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor{
+                BFLog(1, message: "progress is \(progress) i \(lastDrawedLineIndex) 命中的位置:\(CGFloat(lastDrawedLineIndex) * oneMarginTime)")
                 drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
                 drawLayer.setNeedsDisplay()
                 drawLayer.layoutIfNeeded()
             }
+            lastDrawedLineIndex += 1
+
         }
 
         
@@ -317,6 +321,7 @@ class PQStuckPointCuttingView: UIView {
 
     // 竖线恢复到原有色值
     func resetDefaultsColor(clearData:Bool = true) {
+        lastDrawedLineIndex = 0
         for layer in lineLayerArray {
             layer.strokeColor = UIColor.hexColor(hexadecimal: "#999999").cgColor
             layer.setNeedsDisplay()
@@ -336,7 +341,7 @@ class PQStuckPointCuttingView: UIView {
     }
 
     /// 生成波纹
-    /// - Parameter waveArr: <#waveArr description#>
+    /// - Parameter waveArr: <#waveArr description#> // warning 有崩溃 _buffer    _ArrayBuffer<CoreGraphics.CGFloat>    wavearr为CoreGraph.CGFloat数组
     /// - Returns: <#description#>
     func createWave(waveArr: [CGFloat]) {
         for (i, power) in waveArr.enumerated() {