我想把這個例子http://lepetit-prince.net/ios/?p=1510翻譯成RubyMotion,我創建的'餅片'都沒有顯示在屏幕上。我沒有在示例中使用for循環,因爲我只使用餅圖的兩個「切片」。有任何想法嗎?RubyMotion餅圖CALayer
chart = UIView.alloc.initWithFrame(CGRect.new([60, 100], [200, 200]))
chart.backgroundColor = UIColor.colorWithRed(0, green:0, blue:0, alpha:0.5)
chart.layer.cornerRadius = 100
@window.addSubview(chart)
green = 70.0
red = 30.0
red = red/100.0 * 2.0 * Math::PI
green = green/100 * 2.0 * Math::PI
start = 0.0
path = UIBezierPath.alloc.init
finish = start + red
sa = start - Math::PI/2.0
ea = finish - Math::PI/2.0
puts sa, ea
path.moveToPoint(CGPoint.new(100, 100))
path.addArcWithCenter(CGPoint.new(100, 100), radius:100, startAngle:sa, endAngle:ea, clockwise:true)
sl = CAShapeLayer.alloc.init
sl.fillColor = UIColor.redColor
sl.path = path.CGPath
chart.layer.addSublayer(sl)
start = finish
path = UIBezierPath.alloc.init
finish = start + green
sa = start - Math::PI/2.0
ea = finish - Math::PI/2.0
path.moveToPoint(CGPoint.new(100, 100))
path.addArcWithCenter(CGPoint.new(100, 100), radius:100, startAngle:sa, endAngle:ea, clockwise:true)
sl = CAShapeLayer.alloc.init
sl.fillColor = UIColor.greenColor
sl.path = path.CGPath
chart.layer.addSublayer(sl)
mask = UIView.alloc.initWithFrame(CGRect.new([0, 0], [196, 196]))
mask.layer.cornerRadius = 98
mask.center = CGPoint.new(100, 100)
mask.backgroundColor = UIColor.whiteColor
chart.addSubview(mask)
嘗試移動''@ window.addSubview(圖) ''到最後一行 – ahmet 2014-09-20 22:59:34
不幸伊利沒有工作 – 2014-09-21 01:07:46