【发布时间】:2019-11-10 14:20:35
【问题描述】:
我的代码结果是在我已经画线之后,它会检测到正确或错误的位置并显示结果,但是在我已经画完之后它会突然显示结果。我希望它在绘制超过 1 条线后显示结果。我该怎么办?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let touch = touches.first
swiped = false
lastPoint = touch?.location(in: self)
firstPoint = lastPoint
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if let touch = touches.first {
swiped = true
currentPoint = touch.location(in: self)
drawShapeLayer(from: lastPoint, to: currentPoint)
lastPoint = currentPoint
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
if !swiped {
drawShapeLayer(from: lastPoint, to: lastPoint!)
}
if c1.contains(firstPoint) && c3.contains(linePoint) && c2.contains(lastPoint){
AlertView.instance.showAlert(title: "Hooray!", message: "You made it!", alertType : .success)
}
else {
AlertView.instance.showAlert(title: "Oops!", message: "You've almost got it.", alertType : .failure)
}
}
【问题讨论】:
标签: ios swift touch draw cgpath