3 votes

SwiftUI : Parcours UIkit UIbezier vers SwiftUI

J'essaie de convertir UIBezierPath en SwiftUI Path.

J'ai réussi à le faire manuellement, en modifiant le code ci-dessous :

De :

UIBezierPath controlPoint1 : CGPoint(x : 1226.38, y : 0), controlPoint2 : CGPoint(x : 1199.37, y : 0))

A :

SwiftUI contrôle1 : CGPoint(x : 1226.38, y : 0), control2 : CGPoint(x : 1199.37, y : 0))

Exemple d'un code de chemin complet :

       let stroke253 = UIBezierPath()
            stroke253.move(to: CGPoint(x: 1253.45, y: 0))
            stroke253.addCurve(to: CGPoint(x: 1172.3, y: 0), controlPoint1: CGPoint(x: 1226.38, y: 0), controlPoint2: CGPoint(x: 1199.37, y: 0))
            stroke253.addCurve(to: CGPoint(x: 990.46, y: 0), controlPoint1: CGPoint(x: 1111.66, y: 0), controlPoint2: CGPoint(x: 1051.12, y: 0))
            stroke253.addCurve(to: CGPoint(x: 808.64, y: 0), controlPoint1: CGPoint(x: 929.82, y: 0), controlPoint2: CGPoint(x: 869.27, y: 0))
            stroke253.addCurve(to: CGPoint(x: 626.74, y: 0), controlPoint1: CGPoint(x: 747.98, y: 0), controlPoint2: CGPoint(x: 687.4, y: 0))
            stroke253.addCurve(to: CGPoint(x: 444.84, y: 0), controlPoint1: CGPoint(x: 566.08, y: 0), controlPoint2: CGPoint(x: 505.5, y: 0))
            stroke253.addCurve(to: CGPoint(x: 263, y: 0), controlPoint1: CGPoint(x: 384.18, y: 0), controlPoint2: CGPoint(x: 323.63, y: 0))
            stroke253.addCurve(to: CGPoint(x: 81.18, y: 0), controlPoint1: CGPoint(x: 202.37, y: 0), controlPoint2: CGPoint(x: 141.82, y: 0))
            stroke253.addCurve(to: CGPoint.zero, controlPoint1: CGPoint(x: 54.11, y: 0), controlPoint2: CGPoint(x: 27.07, y: 0))
            context.saveGState()
            context.translateBy(x: 128.21, y: 144.05)
            stroke253.lineWidth = 2
            UIColor(hue: 1, saturation: 0.636, brightness: 0.549, alpha: 1).setStroke()
            stroke253.stroke()
            context.restoreGState()

            context.restoreGState()
        }

import SwiftUI

struct PatternScene: View {
   let stroke253 = Path { stroke253 in
       stroke253.move(to: CGPoint(x: 1253.45, y: 0))
    stroke253.addCurve(to: CGPoint(x: 1172.3, y: 0), control1: CGPoint(x: 1226.38, y: 0), control2: CGPoint(x: 1199.37, y: 0))
    stroke253.addCurve(to: CGPoint(x: 990.46, y: 0), control1: CGPoint(x: 1111.66, y: 0), control2: CGPoint(x: 1051.12, y: 0))
    stroke253.addCurve(to: CGPoint(x: 808.64, y: 0), control1: CGPoint(x: 929.82, y: 0), control2: CGPoint(x: 869.27, y: 0))
    stroke253.addCurve(to: CGPoint(x: 626.74, y: 0), control1: CGPoint(x: 747.98, y: 0), control2: CGPoint(x: 687.4, y: 0))
    stroke253.addCurve(to: CGPoint(x: 444.84, y: 0), control1: CGPoint(x: 566.08, y: 0), control2: CGPoint(x: 505.5, y: 0))
    stroke253.addCurve(to: CGPoint(x: 263, y: 0), control1: CGPoint(x: 384.18, y: 0), control2: CGPoint(x: 323.63, y: 0))
    stroke253.addCurve(to: CGPoint(x: 81.18, y: 0), control1: CGPoint(x: 202.37, y: 0), control2: CGPoint(x: 141.82, y: 0))
    stroke253.addCurve(to: CGPoint.zero, control1: CGPoint(x: 54.11, y: 0), control2: CGPoint(x: 27.07, y: 0))
    }

    var body: some View {
        self.stroke253
            .stroke(Color.blue, lineWidth: 10)

    }
}

struct PatternScene_Previews: PreviewProvider {
    static var previews: some View {
        PatternScene()
    }
}

Question : comment puis-je faire cela sans éditer manuellement ?

Toute aide est la bienvenue !

salutations

3voto

E.Coms Points 3519

Je ne comprends pas bien votre question, ou il me manque des informations. Mais si vous avez besoin de convertir un UIBezierPath à Path :

Path(UIBezierPath().cgPath) ou Path(stroke253.cgPath) comme variable.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X