我写了一些代码来围绕定位在自定义视图中心的圆圈放置对象,但它并不完美地围绕圆圈.我不知道代码在哪里出错了.
这是代码:
func createObjectsAroundCircle() {
let center = CGPointMake(bounds.width/2 ,bounds.height/2)
let radius : CGFloat = 100
let count = 20
var angle = CGFloat(2 * M_PI)
let step = CGFloat(2 * M_PI) / CGFloat(count)
let circlePath = UIBezierPath(arcCenter: center, radius: radius, startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.CGPath
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.strokeColor = UIColor.redColor().CGColor
shapeLayer.lineWidth = 3.0
self.layer.addSublayer(shapeLayer)
// set objects around circle
for var index = 0; index < count ; index++ …
Run Code Online (Sandbox Code Playgroud)