Search code examples
swiftuigesturerecognizertvos

Is it possible to add a custom gesture recognizer to a view in TVOS app?


In my TVOS app I created a custom gesture recognizer, which is a subclass of a UIGestureRecognizer.

Later in the code I'm trying to add it to a collection view cell.

let customGest:CustomGestureRecognizer = CustomGestureRecognizer(target: self, action: Selector("myMethod:"))
cell.addGestureRecognizer(customGest)

in the debugger I see that my gesture recognizer is getting initialized properly. However, none of it's touches methods are getting called (touchesBegan, touchesMoved..).

I've done this in iOS just fine, so I'm curious if it is possible to do so in TVOS?

Any kind of help is highly appreciated.


Solution

  • Touch events (UITouch) and button press events (UIPress) are first delivered to the focused view, and then they go up the responder chain from there. So your custom gesture recognizer will only fire if the cell you added it to is focused, or if the cell contains the focused view as a descendant.

    Is the cell you're adding this gesture to focused (or contain the focused view)?