Gol*_*rii 4 xcode core-animation core-graphics ios swift
我有一个 UIBezierPath 画线器
let line = CAShapeLayer()
line.path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: CGFloat(114.0/180.0) * .pi,
endAngle: .pi,
clockwise: true).cgPath
line.lineWidth = LINE_WIDTH
line.strokeColor = UIColor.red.withAlphaComponent(0.9).cgColor
line.fillColor = UIColor.clear.cgColor
Run Code Online (Sandbox Code Playgroud)
我尝试通过添加一些新的 CAShapeLayer() 来圆角
let corner = CAShapeLayer()
corner.path = UIBezierPath(arcCenter: coordByCorner(114.0*1.00035),
radius: LINE_WIDTH/2,
startAngle: CGFloat(114.0/180.0) * .pi,
endAngle: CGFloat(114.0/180.0 + 1) * .pi,
clockwise: false).cgPath
corner.strokeColor = UIColor.clear.cgColor
corner.fillColor = UIColor.red.withAlphaComponent(0.9).cgColor
line.addSublayer(corner)
Run Code Online (Sandbox Code Playgroud)
但我认为这是非常糟糕的变体,当我改变图层的颜色时,颜色会随着不同的时间间隔而变化。
此外,这一切看起来像这样:
PS: 1.00035 有消除层间间隙的作用。并且 alpha 需要 < 1.0 (0.1 - 0.9),那么它是如何不透明的呢?
Gol*_*rii 10
通过添加 kCALineCapRound 解决的问题
let line = CAShapeLayer()
line.path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: CGFloat(114.0/180.0) * .pi,
endAngle: .pi,
clockwise: true).cgPath
line.lineWidth = LINE_WIDTH
line.strokeColor = UIColor.red.withAlphaComponent(0.9).cgColor
line.fillColor = UIColor.clear.cgColor
line.lineCap = kCALineCapRound // this parameter solve my problem
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2205 次 |
最近记录: |