2017-04-18 147 views
1

I'm新斯威夫特3和我正尝试将功能转化为斯威夫特3:CGPathCreateCopyByTransformingPath斯威夫特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]; 
     } 
    } 
} 

我已经到目前为止这一点,但我还没有豆能这部分翻译:

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

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

I'm这样的:

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) 
       } 
      } 
     } 
    } 
} 

I'm收到此错误:

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

我没有发现任何在网络上,但这样的:

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

但我不能使它发挥作用。

在此先感谢。

快乐编码。

回答

2

这行不正确:

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

.copy(using:)是一个实例方法,而不是一个类方法。您的意思是(根据原始代码):

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