簡體   English   中英

touches開始無法進行多次觸摸

[英]touchesBegan not working for multiple touches

我的touchesBegan對於發生的每個不同的觸摸事件均能正常工作,但當我同時在兩個單獨的位置觸摸時除外。 我總是必須舉起一根手指才能放下另一根手指。 有什么辦法可以讓touchesBegan(並希望touchesMoved)同時為兩個不同的觸摸工作? 在我的項目中,我有一把劍,如果您單擊手柄,它將平移劍,如果您單擊刀片,它將旋轉劍,但是如果您單擊兩者,劍將飛過整個屏幕。

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    /* Called when a touch begins */
    for touch in (touches as! Set<UITouch>) {
        let location = touch.locationInNode(self)
        dx = location.x - Handle.position.x
        dy = location.y - Handle.position.y
        locationAngle = atan2(dy, dx)
        if (HandleTouch.containsPoint(location)){
            touchedHandle = true
        }
        else if (BladeTouch.containsPoint(location)){
            touchedBlade = true
        }
    }
}

確保將視圖的multipleTouchEnabled屬性設置為true ,您可以在代碼中或通過Interface Builder中的“ Multiple Touch”復選框來執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM