Mar*_*coz 4 objective-c cgpath ios swift swift3
我是Swift 3的新手,我正在尝试将该函数转换为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];
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经做了这个,但我没有能够翻译这部分:
CGAffineTransform zoom = CGAffineTransformMakeScale(self.scale, self.scale);
CGPathRef movedPath = CGPathCreateCopyByTransImformingPath([area.pathArea CGPath], &zoom);
area.pathAreaTransformed = [UIBezierPath bezierPathWithCGPath:movedPath];
Run Code Online (Sandbox Code Playgroud)
我是这样的:
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)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
成员'副本的模糊引用(dashingWithPhase:lengths:transform :)'
我在网上什么都没找到但是这个:
但我不能让它发挥作用.
提前致谢.
快乐的编码.
这行不正确:
var movedPath = CGPath.copy(using: &zoom)
Run Code Online (Sandbox Code Playgroud)
.copy(using:)是一个实例方法,而不是类方法.你的意思是(根据原始代码):
let movedPath = area.pathArea.cgPath.copy(using: &zoom)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1123 次 |
| 最近记录: |