0
您是否必須設置界限CAShapeLayer
?CAShapeLayer - 界限
我正在創建一個形狀圖層,並通過一個UIBezierPath
爲其分配一個路徑,該圖形是一個簡單的視圖大小的圓。
我沒有在圖層上設置任何position
或bounds
,這是錯誤的嗎?
class View: UIView {
...
var backgroundLayer: CAShapeLayer!
func setup() {
// call from init
backgroundLayer = CAShapeLayer()
backgroundLayer.strokeColor = UIColor.redColor()
backgroundLayer.lineWidth = 3
backgroundLayer.fillColor = UIColor.clearColor().CGColor
layer.addSublayer(backgroundLayer)
...
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundLayer?.path = circlePath(100)
...
}
func circlePath(progress: Int) -> CGPath {
let path = UIBezierPath()
let inverseProgress = 1 - CGFloat(progress)/100
let endAngleOffset = CGFloat(2 * M_PI) * inverseProgress
path.addArcWithCenter(localCenter, radius: radius, startAngle: CGFloat(-M_PI), endAngle: CGFloat(M_PI) - endAngleOffset, clockwise: true)
return path.CGPath
}
...
}
晶瑩剔透。 –