【发布时间】:2016-10-25 19:08:44
【问题描述】:
正如标题所说,我怎样才能做到这一点?我可以进行第一次触摸,但如果是滑动手势,我不知道如何进行最后一次触摸。使用以下代码,我得到错误:“Set”类型的值没有成员“last”。不确定如何在释放触摸时获得位置。
override func touchesMoved(_ touches: Set<UITouch>, with: UIEvent?){
let firstTouch:UITouch = touches.first! as UITouch
let lastTouch:UITouch = touches.last! as UITouch
let firstTouchLocation = firstTouch.location(in: self)
let lastTouchLocation = lastTouch.location(in: self)
}
我想获取第一个点的位置和第二个点的位置。然后我想使用滑动的持续时间、线条的大小和线条的角度来创建一个脉冲向量以在 SKNode 上使用。有没有办法使用 UITouch 提取这些信息?任何帮助是极大的赞赏。感谢您的宝贵时间!
我在屏幕上也有基本的触摸来运行功能
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first! as UITouch
let touchLocation = touch.location(in: self)
if playButton.contains(touchLocation) && proceed == true{
playSound1()
Ball.physicsBody?.affectedByGravity = true
proceed = false}
else if infoButton.contains(touchLocation) && proceed == true{
playSound1()
loadScene2()}
else {}
}
【问题讨论】:
-
touches集合包含单个(开始/移动/结束)事件的所有手指触摸屏幕的位置,而不是动作的“开始”和“结束”位置。
标签: uikit swift3 uitouch uievent touchesended