- fixed: unable to setup updated pressure curve mapping during streaming

- flexible pressure curve start point
- larger pressure curve view
This commit is contained in:
True Zhuanjia committed 2026-02-24 16:49:31 +08:00
1 parent f6017824ee
commit 470862dbe0
2 files changed
+14 -8

No files matched your search

+1
View File
@@ -75,6 +75,7 @@ import UIKit
confirmAction.setValue(buttonTitle, forKey: "title") confirmAction.setValue(buttonTitle, forKey: "title")
if autoCompletion { if autoCompletion {
autoCompletion = false autoCompletion = false
completion?()
alertController.dismiss(animated: false) alertController.dismiss(animated: false)
return return
} }
+13 -8
View File
@@ -114,6 +114,9 @@ final class PressureCurve {
func value(at x: CGFloat) -> CGFloat { func value(at x: CGFloat) -> CGFloat {
guard let firstPoint = polylinePoints.first else { return 0 }
if x < firstPoint.x {return 0}
let xClamped = min(max(x, 0), 1) let xClamped = min(max(x, 0), 1)
let segments = cachedSegments let segments = cachedSegments
@@ -230,7 +233,7 @@ final class PressureCurveView: UIView {
let curve = PressureCurve() let curve = PressureCurve()
private var draggingIndex: Int? = nil private var draggingIndex: Int? = nil
private let hitRadius: CGFloat = 22 private let hitRadius: CGFloat = 35
enum PressureTestStage: UInt8 { enum PressureTestStage: UInt8 {
case drawingStage case drawingStage
@@ -288,7 +291,7 @@ final class PressureCurveView: UIView {
private func drawCurve(_ ctx: CGContext) { private func drawCurve(_ ctx: CGContext) {
ctx.setStrokeColor(UIColor.systemBlue.cgColor) ctx.setStrokeColor(UIColor.systemBlue.cgColor)
ctx.setLineWidth(5) ctx.setLineWidth(6)
let points = curve.sampleCurve(stepsPerSegment: 60) let points = curve.sampleCurve(stepsPerSegment: 60)
for (i,p) in points.enumerated() { for (i,p) in points.enumerated() {
let mapped = map(p) let mapped = map(p)
@@ -300,7 +303,7 @@ final class PressureCurveView: UIView {
private func drawTangents(_ ctx: CGContext) { private func drawTangents(_ ctx: CGContext) {
let pts = curve.tangentPoints let pts = curve.tangentPoints
ctx.setStrokeColor(UIColor.systemPurple.cgColor) ctx.setStrokeColor(UIColor.systemPurple.cgColor)
ctx.setLineWidth(2.5) ctx.setLineWidth(2)
for i in 0..<pts.count { for i in 0..<pts.count {
let p = map(pts[i]) let p = map(pts[i])
if i==0 { ctx.move(to:p) } else { ctx.addLine(to:p) } if i==0 { ctx.move(to:p) } else { ctx.addLine(to:p) }
@@ -309,9 +312,9 @@ final class PressureCurveView: UIView {
for p in pts { for p in pts {
let c = map(p) let c = map(p)
let r: CGFloat = 4 let r: CGFloat = 16
ctx.setFillColor(UIColor.systemPurple.cgColor) ctx.setFillColor(UIColor.systemPurple.cgColor)
ctx.fill(CGRect(x:c.x-r, y:c.y-r, width:r*2, height:r*2)) ctx.fill(CGRect(x:c.x-r/2, y:c.y-r/2, width:r, height:r))
} }
} }
@@ -390,7 +393,9 @@ final class PressureCurveView: UIView {
var point = unmap(location) var point = unmap(location)
if draggingIndex == 0 { if draggingIndex == 0 {
point.x = 0 let nextPoint = curve.polylinePoints[idx+1]
point.x = min(max(point.x, 0), nextPoint.x)
// point.x = 0
point.y = min(max(point.y, 0), 1) point.y = min(max(point.y, 0), 1)
} }
else if draggingIndex == curve.polylinePoints.count-1 { else if draggingIndex == curve.polylinePoints.count-1 {
@@ -499,8 +504,8 @@ class PressureCurveViewController: UIViewController {
self.view.isOpaque = false self.view.isOpaque = false
self.view.backgroundColor = UIColor.clear // 半透明遮罩 self.view.backgroundColor = UIColor.clear // 半透明遮罩
let curveWidth: CGFloat = 400 let curveWidth: CGFloat = 530
let curveHeight: CGFloat = 400 let curveHeight: CGFloat = 530
curveView = PressureCurveView(frame: CGRect(x: 0, y: 0, width: curveWidth, height: curveHeight)) curveView = PressureCurveView(frame: CGRect(x: 0, y: 0, width: curveWidth, height: curveHeight))
curveView.center = self.view.center curveView.center = self.view.center
curveView.backgroundColor = .white curveView.backgroundColor = .white