我怎样才能使 UIBezierPath 圆角化?
How I can rounded corners UIBezierPath?
我有一个相机层,您可以在图 1 中看到,我需要一个像图 2 一样的圆角。我如何圆角。
图 1: Image 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)
let cgPath = CGMutablePath()
cgPath.move(to: bottomLeftPoint)
cgPath.addArc(tangent1End: topLeftPoint, tangent2End: topRightPoint, radius: radius)
cgPath.addLine(to: topRightPoint)
let bezierPath = UIBezierPath(cgPath: cgPath)
我有一个相机层,您可以在图 1 中看到,我需要一个像图 2 一样的圆角。我如何圆角。
图 1:
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)
let cgPath = CGMutablePath()
cgPath.move(to: bottomLeftPoint)
cgPath.addArc(tangent1End: topLeftPoint, tangent2End: topRightPoint, radius: radius)
cgPath.addLine(to: topRightPoint)
let bezierPath = UIBezierPath(cgPath: cgPath)