UISwipeGestureRecognizer not being called

Hello all,


Is there a known issue with UISwipeGestureRecognizers in tvOS with SpriteKit? My swipe gestures just don't seem to be getting called. I have the following in my didMoveToView:


        let swipeDown = UISwipeGestureRecognizer(target: self, action: "swiped:")
        swipeDown.direction = UISwipeGestureRecognizerDirection.Down
        view.addGestureRecognizer(swipeDown)
       
        let swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:")
        swipeUp.direction = UISwipeGestureRecognizerDirection.Up
        view.addGestureRecognizer(swipeUp)
       
        let swipeLeft = UISwipeGestureRecognizer(target: self, action: "swiped:")
        swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
        view.addGestureRecognizer(swipeLeft)
       
        let swipeRight = UISwipeGestureRecognizer(target: self, action: "swiped:")
        swipeRight.direction = UISwipeGestureRecognizerDirection.Right
        view.addGestureRecognizer(swipeRight)


I have tap gestures that are called without any issues, but for some reason the swipe gestures aren't being recognized.


Any help would be greatly appreciated. Thanks!

Answered by nthState in 77259022

Other thoughts:


- Are you remembering to remove the swipe gestures from previous scenes ? - if any.

- Are you doing anything with touches which might interfere with the cancelation of gestures ?

Make sure the gesture recognizer allows indirect touches.


swipeDown.allowedTouchTypes = [UITouchType.Indirect].map { $0.rawValue }

Unfortunately it still doesn't recognize the swipe, even after allowing indirect touches.

I was having a hard time getting swipes to work. I'm not using SpriteKit, so yours may be a different issue. But for me I think it was a matter of providing a canBecomeFocused override for the view receiving the swipes:



- (BOOL)canBecomeFocused {

return YES;

}


Bob

I always forget to set userInteractionEnabled to true on views with a gesture recognizer. Maybe you did too?

I always forget as well, but this is one of the rare cases that I didn't. Even after setting userInteractionEnabled to true. Whats particularly confusing is the fact that it the gestures are added to the view without any issues. It's just that the selector is never reached.

Thank you for the suggestion, however I believe since my class isn't a subclass of UIView I won't be able to override the canBecomeFocused method.

In order to use gesture recognizere, don't they have to operate upon a UIView or subset? Whatever view that is, I think it needs to be the focused view.

You are correct. What I did was add the following to the top of my scene class:

public extension SKView {
    override func canBecomeFocused() -> Bool {
        return true
    }
}


This sets canBecomeFocused of the view that my SKScene sits on to true, however the same issue persists. The selector is never reached.

You might try checking to see what is the focused view. I'm not at my computer but I remember some other calls influencing focus - shouldBecomeFocused, maybe? Maybe your problem is unrelated. I spent some time before fixing my problem where I thought it had to do with the firstResponder. You might make sure that is the he correct view.

Accepted Answer

Other thoughts:


- Are you remembering to remove the swipe gestures from previous scenes ? - if any.

- Are you doing anything with touches which might interfere with the cancelation of gestures ?

AH! You are correct. For some reason there were gestures being set up in the main ViewController that I had forgotten were there. Cleaning those up seems to have fixed the issue. Thank you!

UISwipeGestureRecognizer not being called
 
 
Q