我需要画一个圆角矩形。然而,在非常特殊的角半径值(34 到 37 之间)下,它会导致非常奇怪的错误,如下图所示。有人可以向我解释为什么会这样吗?
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
drawView()
self.view.backgroundColor = .red
}
func drawView() {
let rect = CGRect(x: 100, y: 100, width: 200, height: 100)
let borderWidth = 10.0
let cornerRadius = 34.0
let layer = CAShapeLayer()
layer.strokeColor = UIColor.green.cgColor
layer.lineWidth = borderWidth
layer.fillColor = UIColor.white.cgColor
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius)
layer.path = path.cgPath
self.view.layer.addSublayer(layer)
}
}