SwiftUI:渲染路径控制点

时间:2019-12-13 16:19:02

标签: swiftui

使用令人敬畏的“ SwiftUI的同伴”应用中的以下代码,我能够获取控制点位置。

现在,我正在尝试在画布上渲染“路径+控制点”,但无法使其正常工作。

import SwiftUI

struct ContentView: View {
    var body: some View {
        let path = Path(ellipseIn: CGRect(origin: .zero, size: CGSize(width: 50, height: 50)))

        var steps = [String]()

        path.forEach { element in
            switch element {
            case .move(let to):
                steps.append("MOVE TO (\(to.x), \(to.y))")
            case .line(let to):
                steps.append("LINE TO (\(to.x), \(to.y))")
            case .quadCurve(let to, let control):
                steps.append("QUAD CURVE TO (\(to.x), \(to.y)), CONTROL (\(control.x), \(control.y))))")
            case .curve(let to, let control1, let control2):
                steps.append("CURVE TO (\(to.x), \(to.y)), CONTROL1 (\(control1.x), \(control1.y)), CONTROL2 (\(control2.x), \(control2.y))))")
            case .closeSubpath:
                steps.append("CLOSE SUBPATH")
            }
        }

        return VStack {
            ForEach(steps, id: \.self) { step in
                Text(step)
            }
        }
    }

}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

真的很感谢您的帮助!

0 个答案:

没有答案