美文网首页iOS OC 学习手册
Swift UIBezierPath 画圆,确定开始的位置

Swift UIBezierPath 画圆,确定开始的位置

作者: 我为双鱼狂 | 来源:发表于2021-06-07 20:41 被阅读0次

应用场景

自定义画圆或者圆弧。

核心逻辑/代码

使用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)

相关文章

网友评论

    本文标题:Swift UIBezierPath 画圆,确定开始的位置

    本文链接:https://www.haomeiwen.com/subject/uheheltx.html