gpt4 book ai didi

ios - 如何在touchesEnded之后再次使用touchesBegan

转载 作者:行者123 更新时间:2023-11-29 05:19:49 26 4
gpt4 key购买 nike

我的代码结果是在我画线之后,它会检测正确或错误的位置并显示结果,但是在我已经画线之后它会突然显示结果。我希望它在绘制超过 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)
}
}

最佳答案

首先,使用 UISwipeGestureRecognizer 可能会更容易 https://developer.apple.com/documentation/uikit/uiswipegesturerecognizer

它们抽象出很多东西并简化了状态和路径等东西。

其中一些让我感到困惑

if !swiped {
drawShapeLayer(from: lastPoint, to: lastPoint!)
}

难道不是

if !swiped {
let touch = touches.first
lastPoint = touch?.location(in: self)
drawShapeLayer(from: firstPoint, to: lastPoint!)
}

也在这个

  if  c1.contains(firstPoint) && c3.contains(linePoint) && c2.contains(lastPoint){
AlertView.instance.showAlert(title: "Hooray!", message: "You made it!", alertType : .success)
}

不会出现 linePoint != lastPoint 的情况。

除非“drawShapeLayer”更改这些,在这种情况下您的数据封装会有点困惑。

关于ios - 如何在touchesEnded之后再次使用touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58789533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com