【发布时间】:2014-09-20 21:47:14
【问题描述】:
我正在尝试将这个示例 http://lepetit-prince.net/ios/?p=1510 翻译成 RubyMotion,而我创建的两个“饼图”都没有出现在屏幕上。我没有在示例中使用 for 循环,因为我只使用了饼图的两个“切片”。有什么想法吗?
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(chart)移动到最后一行 -
很遗憾没有成功
标签: ruby calayer pie-chart rubymotion