【发布时间】:2024-04-17 20:45:01
【问题描述】:
我有从 touchesBegan 和 touchesMoved 点创建的 UIBezierPath 数组。 我想在屏幕上绘制动画。
不迭代每个贝塞尔曲线并调用 setNeedsDisplay() 的最佳方法是什么?
谢谢
override func draw(_ rect: CGRect) {
for bezier in beziers{
bezier.stroke()
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let cgPoint = touches.first!.location(in: self)
let bezierPath = ColorBezierPath() // subclass of UIBezierPath
bezierPath.lineWidth = lineWidth
bezierPath.color = color
bezierPath.move(to: cgPoint)
beziers.append(bezierPath)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
let cgPoint = touches.first!.location(in: self)
let bezierPath = beziers.last
bezierPath?.addLine(to: cgPoint)
setNeedsDisplay()
}
【问题讨论】:
-
您的需求是否与任何绘图应用有关?
-
@PraveenKumar 是的,类似于“Draw Something”,我想保存 UIBezierPath 数组,然后在动画中显示绘制
-
你说的稍后是什么意思……你不想在画的时候给用户看吗?!
-
我上面写的代码已经做到了。我的意思是稍后在其他设备上显示
标签: ios swift swift3 core-animation uibezierpath