ios - 绘制 UIView 四圆
问题描述
如何像上面那样制作 UIView。
在下面尝试过,但它创建了一个半圆形视图。
let circlePath = UIBezierPath(arcCenter: CGPoint(x: topView.bounds.size.width, y: topView.bounds.size.height / 2), radius: topView.bounds.size.height, startAngle: .pi, endAngle: 0.0, clockwise: false)
let circleShape = CAShapeLayer()
circleShape.path = circlePath.cgPath
topView.layer.mask = circleShape
解决方案
自己画吧。没有什么复杂的。
- 从中心点开始
- 转到底部点(线)
- 从 BottomPoint 到 LeftPoint 的弧线,角度为 Pi/2 到 Pi(顺时针方向)
- Go to leftPoint
- 转到中心点(线)
UIBezierPath
:_
let bezierPath = UIBezierPath()
let centerPoint = CGPoint(x: view.bounds.width, y: 0)
let bottomPoint = CGPoint(x: view.bounds.width, y: view.bounds.height)
let leftPoint = CGPoint(x: 0, y: 0)
bezierPath.move(to: bottomPoint) //not needed
bezierPath.addArc(withCenter: centerPoint,
radius: view.bounds.height,
startAngle: CGFloat.pi/2.0,
endAngle: CGFloat.pi,
clockwise: true)
bezierPath.addLine(to: leftPoint) //not needed
bezierPath.addLine(to: centerPoint)
有两个“不需要”,因为它们是隐含的,但如果它们对您来说“隐藏太多”,您可能想要编写它们。
为什么是你自己?因为,一个圆只有两个点并在它之间填充。换句话说,它不会去“centerPoint”来填充它。我在手工路径中使用的角度相同的示例:
推荐阅读
- json - 在颤振中将 JSON 转换为 ListView.builder
- apache-spark - Spark 结构化流文件接收器创建空 JSON 文件
- python - 有没有办法在 pycharm 中对所有键入的文本启用自定义自动完成功能?
- html - 使用引导程序将两个 div 水平并排水平居中对齐
- spring-boot - 如何使Spring Boot显示目录下的文件列表
- javascript - 如何找到一系列重复数字的总和?
- azure - Azure 应用服务应用程序设置不覆盖 appsettings.json 值
- javascript - 根据提供的值获取指定的对象(键和值)
- google-cloud-firestore - Firestore 发布者能否检测到来自侦听器的订阅?
- rust - Rust 无法分配 Option 内部可变引用