为什么拐角半径的最大值不是矩形的一半?在swift中使用UIBezierPath绘制roundedRect

为什么拐角半径的最大值不是矩形的一半?在swift中使用UIBezierPath绘制roundedRect,swift,core-graphics,quartz-2d,Swift,Core Graphics,Quartz 2d,正如文档中所说的,拐角半径不能大于一半宽度,但在我的代码中,只有1/3的宽度圆矩形变成了一个圆,不知道为什么?需要帮助吗 文件: 转弯半径: 每个角椭圆的半径。值为0时,将生成没有圆角的矩形。大于矩形宽度或高度一半的值将被适当地钳制为宽度或高度的一半 我认为这是因为类型转换错误 试试这个 let xCor: CGFloat = 50.0 let width: CGFloat = 94.0 let height: CGFloat = 94.0 let cornerRadius: CGFloat

正如文档中所说的,拐角半径不能大于一半宽度,但在我的代码中,只有1/3的宽度圆矩形变成了一个圆,不知道为什么?需要帮助吗

文件:

转弯半径: 每个角椭圆的半径。值为0时,将生成没有圆角的矩形。大于矩形宽度或高度一半的值将被适当地钳制为宽度或高度的一半


我认为这是因为类型转换错误

试试这个

let xCor: CGFloat = 50.0
let width: CGFloat = 94.0
let height: CGFloat = 94.0

let cornerRadius: CGFloat = width / 3.0

var path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 200.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()

path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 300.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()
                
path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 400.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()
PS:没有通过运行此代码进行检查。如果这里有任何问题,请告诉我

let xCor: CGFloat = 50.0
let width: CGFloat = 94.0
let height: CGFloat = 94.0

let cornerRadius: CGFloat = width / 3.0

var path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 200.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()

path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 300.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()
                
path = UIBezierPath(roundedRect: CGRect(x: xCor, y: 400.0, width: width, height: height), cornerRadius: cornerRadius)
path.stroke()