现在我被困在这里:
它的实际工作,尽快更新我的2-d阵列和我的“启动”属性,它正在重绘的UIView,但需要大约5秒钟。有没有人知道一个更快的方法来做到这一点?
class CustomView: UIView {
public var context = UIGraphicsGetCurrentContext()
public var redvalues = [[CGFloat]](repeating: [CGFloat](repeating: 1.0, count: 500), count: 500)
public var start = 0
{
didSet{
self.setNeedsDisplay()
}
}
override func draw(_ rect: CGRect
{
super.draw(rect)
context = UIGraphicsGetCurrentContext()
for yindex in 0...499{
for xindex in 0...499 {
context?.setStrokeColor(UIColor(red: redvalues[xindex][yindex], green: 0.0, blue: 0.0, alpha: 1.0).cgColor)
context?.setLineWidth(2)
context?.beginPath()
context?.move(to: CGPoint(x: CGFloat(xindex), y: CGFloat(yindex)))
context?.addLine(to: CGPoint(x: CGFloat(xindex)+1.0, y: CGFloat(yindex)))
context?.strokePath()
}
}
}
}
谢谢你的回答。那么你将如何单独绘制线条?正如我提到的,如果我使用1x1点bezier路径,应用程序变得非常缓慢。 – Manuel
看看这个问题的第一个答案: https://stackoverflow.com/questions/856354/how-do-i-draw-a-line-on-the-iphone –
你好,谢谢,我已经看着答案。我试过这段代码(转换为swift),但我确实需要一个自定义的UIView,并且只能用这个覆盖drawRect,对吧?我需要每秒钟更改线条和颜色(至少)。 – Manuel