uiscrollviewuipangesturerecognizeruiscrollviewdelegateuipinchgesturerecognizertvos

UIScrollView on tvOS


The question is very simple, how to enable scroll and zoom inside a UIScrollView in tvOS?

I tried the same initializer code from iOS and returned the scrollview for the focusedView var, but nothing happens when i touch the remote.

Also, i tried to add another custom UIPanGestureRecognizer to the scrollview and actually it works, but i don't want to handle the pan with custom code, just use the same pan behavior like iOS.

Let me know, thanks.


Solution

  • You can configure the scroll view's built-in pan gesture to recognize touches on the Siri Remote. It doesn't do that automatically, because normally scroll views on tvOS aren't scrolled directly by touches: they're scrolled automatically as focus moves between views within the scroll view.

    If you really want the scroll view to move directly from touches, you'll need to add UITouchTypeIndirect to the allowedTouchTypes of the scroll view's panGestureRecognizer:

    scrollView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
    

    You'll also need to make sure that either the scroll view itself is the focused view, or is a parent of the focused view, since all touches from the remote will start at the center of the focused view: you need to make sure the scroll view is getting hit-tested for the events to work.

    Zooming won't work, because the Siri Remote can only recognize one touch at a time, so you can't do a pinch gesture on it.