0
我試圖實現2個不同的基於觸摸的行爲。第一個行爲的邏輯是這樣的:現在基於第一個或第二個區分觸摸
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInNode(self)
moveViewTo(touchLocation) //moves my view to touchLocation
}
,爲我的第二個問題,我想基於在那裏我有我的手指在屏幕上旋轉視圖。爲此,我嘗試過:
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInNode(self)
rotateViewTo(touchLocation) //rotates my view to face touchLocation
}
現在,我希望這兩種不同的行爲可以同時工作。特別是,我想要第一次觸摸來改變視圖的位置,第二次觸摸來旋轉視圖。
僅當在視圖中有兩個觸摸並且基於第二觸摸改變方向時纔可以旋轉。
有什麼辦法可以區分哪個觸摸是第一個,哪個是第二個?我無法找到區別於touches: Set<NSObject>
的方法,因爲性質上Set
是無序集合。
我曾嘗試類似的東西: 1.申報可選變量firstTouch:'VAR firstTouch:UITouch' 2.在'touchesBegan',商店firstTouch:'firstTouch = touches.first作爲! UITouch' 3.在'touchesMoved'中,執行'println(firstTouch)'。 出於某種原因,我所有的println聲明都表示firstTouch爲零。 –
您是否確定在設置後立即開始設置? –
你的邏輯起作用了,我之前的嘗試一定是錯誤的。非常感謝你。 –