CGMutablePath.addArc在Swift 3中不起作用?

Gol*_*Joe 4 xcode cgpath ios swift

在Xcode 8 beta 6中,添加路径的一些函数发生了变化,包括添加弧的函数:

func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, transform: CGAffineTransform = default)
Run Code Online (Sandbox Code Playgroud)

除了函数的定义之外,Apple的网站上没有文档.我一直无法从这个函数得到一个实际的弧,并且一直依赖于使用切线的第二个版本.任何人都可以提供工作样品吗?可能只是被窃听?

这是一个由变化打破的功能:

public class func createHorizontalArcPath(_ startPoint:CGPoint, width:CGFloat, arcHeight:CGFloat, closed:Bool = false) -> CGMutablePath
    {
        // http://www.raywenderlich.com/33193/core-graphics-tutorial-arcs-and-paths

        let arcRect = CGRect(x: startPoint.x, y: startPoint.y-arcHeight, width: width, height: arcHeight)

        let arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8*arcRect.size.height));
        let arcCenter = CGPoint(x: arcRect.origin.x + arcRect.size.width/2, y: arcRect.origin.y + arcRadius);

        let angle = acos(arcRect.size.width / (2*arcRadius));
        let startAngle = CGFloat(M_PI)+angle // (180 degrees + angle)
        let endAngle = CGFloat(M_PI*2)-angle // (360 degrees - angle)

        let path = CGMutablePath();
        path.addArc(center: arcCenter, radius: arcRadius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
        if(closed == true)
        {path.addLine(to: startPoint)}
        return path;
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*n R 9

您的Swift代码基于http://www.raywenderlich.com/33193/core-graphics-tutorial-arcs-and-paths中的Objective-C代码,其中弧路径创建为

CGPathAddArc(path, NULL, arcCenter.x, arcCenter.y, arcRadius,
             startAngle, endAngle, 0);
Run Code Online (Sandbox Code Playgroud)

特别是,0作为参数传递给最后一个参数bool clockwise.这应该转换为falseSwift,而不是true:

path.addArc(center: arcCenter, radius: arcRadius,
            startAngle: startAngle, endAngle: endAngle, clockwise: false) 
Run Code Online (Sandbox Code Playgroud)