ios - 如何使 UIBezierPath 从视图中间开始(目前它是从视图的左角开始)
问题描述
我正在使用以下代码在其图层上创建带有进度条的圆形视图,但进度条始终从左上角开始,我想让它从视图的顶部中间开始
func buildRoundView1(roundView:UIView,总计:Int,borderColor:UIColor,shapeLayer:CAShapeLayer){
let trackLayer = CAShapeLayer()
let rect = CGRect(x: 0, y: 0, width: roundView.frame.size.width, height: roundView.frame.size.height)
let circularPath = UIBezierPath(roundedRect: rect, cornerRadius: 10)
trackLayer.path = circularPath.cgPath
trackLayer.lineWidth = 4
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = CAShapeLayerLineCap.round
roundView.layer.addSublayer(trackLayer)
shapeLayer.path = circularPath.cgPath
shapeLayer.strokeColor = borderColor.cgColor
shapeLayer.lineWidth = 4
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineCap = CAShapeLayerLineCap.round
shapeLayer.strokeEnd = 0
roundView.layer.addSublayer(shapeLayer)
let basicAnimation = CABasicAnimation(keyPath: "strokeEnd")
let startValue = Double(10800-total).normalize(min: 0.0, max: 10800.0)
basicAnimation.fromValue = 1 - startValue
basicAnimation.toValue = 1
basicAnimation.duration = CFTimeInterval(total)
basicAnimation.fillMode = CAMediaTimingFillMode.backwards
basicAnimation.isRemovedOnCompletion = true
shapeLayer.add(basicAnimation, forKey: "urSoBasic")
}
解决方案
一些想法:
- 制作自己的几何图形,而不是使用
UIBezierPath(roundedRect: rect, cornerRadius: 10)
移动到点、添加线到点、添加曲线到点等来构造它 - 将您得到的路径旋转
UIBezierPath(roundedRect: rect, cornerRadius: 10)
90 度(将其中心平移到原点,旋转它,然后将其平移回来) - 使高度和宽度交换的贝塞尔路径,并通过对其应用变换来旋转 shapeLayer
推荐阅读
- shell - 使用 shell 执行 groovy 脚本
- git - git 重新提交对 subbranch-a 所做的更改到 subbranch-b
- c# - 如果文档太长,PDF 文件会损坏 - itextsharp
- django - Django apache内部服务器错误
- liferay - Liferay:如何使用 groupID 获取友好的 URL 列表
- python - 如何使用 Quart Python 停止将访问日志记录到标准输出
- java - 如何在 Eclipse 中运行 JUnit 5 测试
- android - Webview 到 Coordinator 布局
- regex - 将系统资源动态映射到 apache 中请求的 uri
- angular - 如何在角度 ngfor 中显示来自 Firebase 存储的文件