麻烦在UIView中翻转CoreGraphics颠倒的弧线

时间:2018-11-21 15:09:41

标签: ios swift core-graphics

我在使用UIView中的核心图形api翻转弧时遇到麻烦。

我知道坐标系是不同的。 UIkit通过将坐标系统(以适应我提供的中心)转换为核心图形协调系统,对我有一半帮助。我假设当我使用核心图形API绘制圆弧时,是否通过使用核心图形坐标系绘制圆弧?

我可以顺时针更改为false,它将满足我的需要。这是好习惯吗?

我一直在使用CGAffineTransform的旋转度和缩放比例,但并没有满足我的需求。有什么办法可以在不将时钟变为虚假的情况下扭转弧线吗?

我还使用UIBezierPath绘制了我想要的另一弧形。据我了解,UIBezierPath是CoreGraphics的包装。我想知道如何使用纯CoreGraphics API做到这一点。

其他问题:我的最后一个功能 调用path.stroke()绘制UIBezierPath路径和CGPath arcPath1。怎么来的? 0.o

override func draw(_ rect: CGRect) {
    guard let CGContext = UIGraphicsGetCurrentContext() else { return }
    let boxPath = CGMutablePath()

    boxPath.addLines(between:
    [CGPoint(x: rect.width / 2, y: rect.height),
     CGPoint(x: rect.width / 2, y: rect.height / 2),
     CGPoint(x: rect.width, y: rect.height / 2)])

    CGContext.beginPath() // begin new path
    CGContext.addPath(boxPath.copy(strokingWithWidth: 5.0, lineCap: .square, lineJoin: .round, miterLimit: 0)) // add new path

    CGContext.setFillColor(UIColor.blue.cgColor)
    CGContext.fillPath()

    let arcPath1 = CGMutablePath()
    arcPath1.addArc(center: CGPoint(x: rect.width / 4, y: rect.height / 4 * 3),
                    radius: 20.0,
                    startAngle: CGFloat(180).degreesToRadians,
                    endAngle: CGFloat(360).degreesToRadians,
                    clockwise: true,
                    transform: CGAffineTransform(rotationAngle: CGFloat(0).degreesToRadians))


    CGContext.beginPath()
    CGContext.addPath(arcPath1)
    CGContext.setStrokeColor(UIColor.blue.cgColor)

    let path = UIBezierPath(arcCenter: CGPoint(x: rect.width / 4 * 3, y: rect.height / 4 * 3),
                            radius: 20.0,
                            startAngle: CGFloat(180).degreesToRadians,
                            endAngle: CGFloat(360).degreesToRadians,
                            clockwise: true)

    path.lineWidth = 5.0
    path.stroke()
}

Arcs, left: CG, right: Bezier

0 个答案:

没有答案
相关问题