Reputation: 1864
I'm trying to detect up and down swipes simultaneously on my app. I have a SKScene and I'm adding the gesture recognizer in func didMoveToView: view
I have set the delegate: UIGestureRecognizerDelegate
, and have the following func all returning true.
gestureRecognizerShouldBegin: gestureRecognizer
gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer
gestureRecognizer: shouldReceiveTouch
When I swipe with one finger I can see that shouldRecognizeSimultaneouslyWithGestureRecognizer
is fired and returning true. Func attached to the swipe is working also.
But when I try to swipe in both directions at the same time the corresponding func are not fired and shouldRecognizeSimultaneouslyWithGestureRecognizer
are not fired.
The swipes are working great when I do them separately, but when simultaneously none swipes are executed.
What am I doing wrong here?
Edit:
class GameControlller: SKScene, SKPhysicsContactDelegate, UIGestureRecognizerDelegate {}
Adding the swipes:
override func didMoveToView(view: SKView) {
print("did move to view")
let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(GameControlller.PaddleMoveUp(_:)))
swipeDown.direction = .Down
self.view!.addGestureRecognizer(swipeDown)
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(GameControlller.PaddleMoveDown(_:)))
swipeUp.direction = .Up
self.view!.addGestureRecognizer(swipeUp)
swipeDown.delegate = self
swipeUp.delegate = self
}
The UIGestureRecognizer delegate func:
func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
print("Simultaneous gesture recognizer!")
return true
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
return true
}
Upvotes: 1
Views: 2628
Reputation: 130
I guess you forget set the delegate:
swipeUp.delegate = self
swipeDown.delegate = self
Upvotes: 1