0

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.

Eugene Gordin
  • 4,047
  • 3
  • 47
  • 80

1 Answers1

1

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)?

Justin Voss
  • 6,294
  • 6
  • 35
  • 39
  • it is focussed...I got presses to work...I guess touches are not supported only through the pan – Eugene Gordin Jan 20 '16 at 03:33
  • Touches are definitely supported, there must be another reason why this isn't working. Could there be other gestures on the cell or on other views that could be recognizing earlier, and interfering with your custom gesture? – Justin Voss Jan 20 '16 at 05:47
  • no, there are no other gestures...as for the support comment...I was referencing this answer http://stackoverflow.com/a/32547502/1669582 and my own experience...what I meant is that there is no tap in tvos...there is press only as I see, press has no coordinate references...in my case only the pressesBegan/End/etc are getting called in the custom class. On the other hand using just UIPanGestureRecognizer works. – Eugene Gordin Jan 20 '16 at 06:45
  • You can create a tap gesture recognizer on tvOS, but be aware that by default it will be configured to listen for Select button-press events. You can re-congfigure it to listen for touch-taps, though (similar to iOS) by changing the `allowedPressTypes` and `allowedTouchTypes` properties. – Justin Voss Jan 20 '16 at 09:45
  • I tried that before, but it didn't work....can you post some working code please? – Eugene Gordin Jan 20 '16 at 17:58