我想绘制一组围绕视图边缘的小圆来镜像我在我的应用程序中控制的物理灯光(像素)。这些圈子会频繁改变颜色。所以我创建了一个PixelSimulator对象来将每个圆圈绘制成一个自定义的UIView对象。在UIView :: drawRect()之外绘制UIBezierPath?
下面是相关的代码
class PixelSimulator {
let size: CGSize;
let color: UIColor;
let pixelPath: UIBezierPath;
init (point: CGPoint, size: CGSize, pixel: Pixel) {
self.point = point;
self.size = size;
self.pixel = pixel;
pixelRect = CGRect(origin: point, size: size);
pixelPath = UIBezierPath(ovalInRect: pixelRect);
color = pixel.color;
}
func render() {
UIGraphicsBeginImageContext(size);
color.setFill();
pixelPath.fill();
UIGraphicsEndImageContext();
}
}
我试着用CGContextAddEllipseInRect(context, pixelRect)
无济于事了不同的方法。我也试过在render()
方法里面声明pixelPath,但也无济于事。
我需要改变什么才能让我的贝塞尔路径随时在drawRect()
的屏幕上画出来吗?
您的图像上下文有什么计划?你什么时候打电话给渲染? – Wain
当相应的物理光源颜色发生变化时,我会调用'render()'。 – turibe
从哪里?在抽签?设置视图以在更改时显示?我不会使用图像上下文,我会直接绘制视图或图层。 – Wain