基本上我想創建一個計時器應用程序。這就是爲什麼我需要一個圓圈來顯示計時器的進度。如果定時器爲10秒,則該圓圈將被分成10段,每段在1秒後出現。好的。如何在swift中從第一象限分割圓圈
我已經成功地從SO post -> draw-a-circular-segment-progress-in-swift創建它,但有點問題。我的圈子的分段從第四個四分體開始,但不是預期的。我想要顯示來自第一個quadrent的段。在這裏我已經爲8段創建了這個函數。
請提供可以動態使用的建議。
func createCircle(){
let circlePath = UIBezierPath(arcCenter: CGPoint(x: view.frame.size.width/2,y: view.frame.size.height/2), radius: CGFloat(90), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let segmentAngle: CGFloat = (360 * 0.125)/360
for i in 0 ..< 8 {
let circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
// start angle is number of segments * the segment angle
circleLayer.strokeStart = segmentAngle * CGFloat(i) //I think all is for this line of code.
print("\nStroke \(i): ",segmentAngle * CGFloat(i))
// end angle is the start plus one segment, minus a little to make a gap
// you'll have to play with this value to get it to look right at the size you need
let gapSize: CGFloat = 0.008
circleLayer.strokeEnd = circleLayer.strokeStart + segmentAngle - gapSize
circleLayer.lineWidth = 10
circleLayer.strokeColor = UIColor(red:0, green:0.004, blue:0.549, alpha:1).CGColor
circleLayer.fillColor = UIColor.clearColor().CGColor
// add the segment to the segments array and to the view
segments.insert(circleLayer, atIndex: i)
}
for i in 0 ..< 8{
view.layer.addSublayer(segments[i])
}
}
我用過你的線,但沒有線段。所以我打印你的價值,它顯示負值,但價值將[0,1] .....這就是爲什麼它不工作。 – KhanShaheb
謝謝.....很多謝謝:) – KhanShaheb