我怎样才能圆角UIBezierPath?

Val*_*riy 0 ios uibezierpath swift

我有一个用于相机的图层,您可以在图 1 中看到,我需要像图 2 那样的圆角。我如何将其圆化。

图片1:在此输入图像描述图片2:在此输入图像描述

    if cornerRadius > cornerLength { cornerRadius = cornerLength }
    if cornerLength > maskContainer.width / 2 { cornerLength = maskContainer.width / 2 }

    let upperLeftPoint = CGPoint(x: maskContainer.minX, y: maskContainer.minY)

    let upperLeftCorner = UIBezierPath()
    upperLeftCorner.move(to: upperLeftPoint.offsetBy(dx: 0, dy: cornerLength))
    upperLeftCorner.addArc(withCenter: upperLeftPoint.offsetBy(dx: cornerRadius, dy: cornerRadius),
                           radius: cornerRadius, startAngle: .pi, endAngle: 3 * .pi / 2, clockwise: true)
    upperLeftCorner.addLine(to: upperLeftPoint.offsetBy(dx: cornerLength, dy: 0))

    let combinedPath = CGMutablePath()
    combinedPath.addPath(upperLeftCorner.cgPath)
Run Code Online (Sandbox Code Playgroud)

小智 5

let cgPath = CGMutablePath()
cgPath.move(to: bottomLeftPoint)
cgPath.addArc(tangent1End: topLeftPoint, tangent2End: topRightPoint, radius: radius)
cgPath.addLine(to: topRightPoint)
let bezierPath = UIBezierPath(cgPath: cgPath)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述