应用场景
自定义画圆或者圆弧。
核心逻辑/代码
使用UIBezierPath(arcCenter: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool)
方法设置画圆的属性。
方法中的参数:
- arcCenter 圆心坐标
- radius 圆半径
- startAngle 起始的弧度
- endAngle 结束的弧度
- clockwise true 为顺时针,fale 为逆时针
0 弧度的起点位置
0 弧度的起点是最右侧,上下居中的位置。
各个点的位置 (top, left, bottom, right) == (1.5 PI, 1 PI, 0.5 PI, 0 PI) - 顺时针方向
弧度不是角度
弧度时 Double.pi
- PI 对应 180 度
- PI_2 对应 90 度
- PI_4 对应 45 度
示例代码
let path = UIBezierPath(arcCenter: CGPoint(x: frame.size.width/2, y: frame.size.height/2),
radius: frame.size.height/2 - CGFloat(borderWidth),
startAngle: start.toRadians(),
endAngle: end.toRadians(),
clockwise: true)
网友评论