【发布时间】:2017-08-22 11:56:38
【问题描述】:
我想在核心图形中绘制不止一条直线。或保存该行并开始一个新的。我使用了两个变量作为触摸位置,并在 touch Began,Moved,Ended 中为它们分配了触摸位置,然后我使用了这个:
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.setStrokeColor(UIColor(red: 0, green: 0, blue: 0, alpha: 1.0).cgColor)
context?.setLineWidth(5.0)
context?.move(to: CGPoint(x: firstTouchLocation.x, y: firstTouchLocation.y))
context?.addLine(to: CGPoint(x: lastTouchLocation.x, y: lastTouchLocation.y))
context?.strokePath()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
firstTouchLocation = touch.location(in: self)
lastTouchLocation = firstTouchLocation
setNeedsDisplay()
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
lastTouchLocation = touch.location(in: self)
setNeedsDisplay()
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
lastTouchLocation = touch.location(in: self)
setNeedsDisplay()
}
}
【问题讨论】:
-
那有什么问题?
-
线路消失并开始新的我想保存线路并开始新的
-
@MohmedShowekh 你会在问题中添加描述问题评论吗
标签: ios swift core-graphics