使用swift绘制SVG图层

时间:2018-02-17 08:36:28

标签: ios swift svg drawing cashapelayer

enter image description here您好我想在svg图层中绘制线条,或者您可以在视图代码的cashapelayers中说是绘制线条的工作但它也在外面绘制任何建议或帮助以避免这种感谢。 这是我的代码,

请检查附加图像我想要这样的东西。

 open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

        let touch = touches.first!
        currentPoint = touch.location(in: self)
        self.pointMoved = true
        let scaleTransform = CGAffineTransform(scaleX: 1 / scaleForCTM, y: 1 / scaleForCTM)
        let scaledPoint = currentPoint.applying(scaleTransform)
        let translateTransform = CGAffineTransform(translationX: -translateForCTM.x, y: -translateForCTM.y)
        let translatedPoint = scaledPoint.applying(translateTransform)



        if let layer = self.drawingLayer?.hitTest(translatedPoint) as? CAShapeLayer {

         //   let point = CGPoint(x: translatedPoint.x, y: translatedPoint.y)
          //  setNeedsDisplay()
       //     drawLine(from: lastPoint, to: currentPoint,layer: layer)
                // 7
            if let layer1 = layer.hitTest(translatedPoint) as? CAShapeLayer { // If you hit a layer and if its a Shapelayer


                let   currentPoint1 = (self.drawingLayer?.convert(translatedPoint, to: layer1))!
                if layer.path!.contains(currentPoint1) {
                 //   print ("We tapped the square")

            //    print(currentPoint1)
                //drawLine(from: lastPoint, to: currentPoint1, layer: layer1)

               // print("current--\(currentPoint1) --- prev--\(lastPoint)")
              drawLineFromPointToPoint(startX: Int((lastPoint.x)), toEndingX: Int((currentPoint1.x)), startingY: Int((currentPoint1.y)), toEndingY: Int((lastPoint.y)), ofColor: fillColor, widthOfLine: 10, inLayer:layer1)
                lastPoint = currentPoint1
                }
 }

          //  let point_layer = CALayer(layer: (self.layer.presentation()?.hitTest(translatedPoint)))

         //   drawLineFromPoint(start: lastPoint, toPoint: currentPoint, ofColor: fillColor, inLayer: layer)


            self.shapesLayers?.append(layer)
        }

        self.setNeedsDisplay()

        //self.strokePath()
    }

0 个答案:

没有答案