2017-04-18 6 views
1

Ich bin neu zu Swift 3 und ich versuche die Funktion Swift zu übersetzen 3:CGPathCreateCopyByTransformingPath zu Swift 3

- (void) drawRect: (CGRect)rect 
{ 
    if (self.editionMode == Zoom) { 

     for (Area *area in self.mArrayPaths) { 

      CGAffineTransform zoom = CGAffineTransformMakeScale(self.scale, self.scale); 

      CGPathRef movedPath = CGPathCreateCopyByTransformingPath([area.pathArea CGPath],               &zoom); 
      area.pathAreaTransformed = [UIBezierPath bezierPathWithCGPath:movedPath]; 


      [area.fillColor setFill]; 
      [area.strokeColor setStroke]; 

      [area.pathAreaTransformed fill]; 
      [area.pathAreaTransformed stroke]; 
     } 
    } 
    else if (self.editionMode == MoveShapes) { 

     [self.currentArea.fillColor setFill]; 
     [self.currentArea.pathAreaShift fill]; 
     [self.currentArea.pathAreaShift stroke]; 

     for (Area *area in self.mArrayPaths) { 

      if (area == self.currentArea) { 

       continue; 
      } 

      [area.fillColor setFill]; 
      [area.strokeColor setStroke]; 

      [area.pathArea fill]; 
      [area.pathArea stroke]; 
     } 

    } else { 

     [self.currentArea.fillColor setFill]; 
     [self.currentArea.pathArea fill]; 
     [self.currentArea.pathArea stroke]; 

     for (Area *area in self.mArrayPaths) { 

      [area.fillColor setFill]; 
      [area.strokeColor setStroke]; 

      [area.pathArea fill]; 
      [area.pathArea stroke]; 
     } 
    } 
} 

ich bisher gemacht haben, dieses aber ich habe nicht bean der Lage, diesen Teil zu übersetzen :

CGAffineTransform zoom = CGAffineTransformMakeScale(self.scale, self.scale); 

    CGPathRef movedPath = CGPathCreateCopyByTransImformingPath([area.pathArea CGPath], &zoom); 
    area.pathAreaTransformed = [UIBezierPath bezierPathWithCGPath:movedPath]; 

ich bin dies:

override func draw(_ rect: CGRect) { 
    if self.editionMode == EditionMode.Zoom { 

     for area in self.mArrayPaths { 

      if let area = area as? Area { 
       var zoom: CGAffineTransform = CGAffineTransform.init(scaleX: self.scale, y: self.scale) 

       var movedPath = CGPath.copy(using: &zoom) 

       if let movedPath = movedPath { 
        area.pathAreaTransformed = UIBezierPath(cgPath: movedPath) 
       } 
      } 
     } 
    } 
} 

bin ich immer diese Fehlermeldung:

Ambiguous reference to member 'copy(dashingWithPhase:lengths:transform :) '

Ich habe nichts auf dem Netz, aber diese gefunden:

https://developer.apple.com/reference/coregraphics/1411161-cgpathcreatecopybytransformingpa?language=objc

Aber ich kann es nicht machen.

Vielen Dank im Voraus.

Glückliche Kodierung.

Antwort

2

Diese Zeile ist falsch:

var movedPath = CGPath.copy(using: &zoom) 

.copy(using:) ist eine Instanz-Methode, keine Klassenmethode. Sie meinten (gemäß dem ursprünglichen Code):

let movedPath = area.pathArea.cgPath.copy(using: &zoom)