UIScrollView on tvOS
H

2

8

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.

Hut answered 16/9, 2015 at 0:38 Comment(0)
G
25

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.

Gondolier answered 16/9, 2015 at 2:29 Comment(6)
But you can't zoom only on simulator? What about the real Apple Remote?Hut
Just a note on zoom. You can get it to work but you'll have to use a different gesture e.g a double tap to zoom in and a double tap to zoom out on the scrollview.Radiography
But how to actually make the scroll view focused? I have another scroll view that has items with focus and I need to switch between these scroll views.Pitsaw
Ok answering to myself: simply override method canBecomeFocusedPitsaw
I have this working but I noticed that the scrolling is unreliable, some of my gestures don't trigger a response. I have the feeling that some other recognizer is processing touches before, and these get delayed or discarded before reaching the pan recognizer, but don't know how to avoid that.Kakaaba
Is there any way to leave the focus again? For instance when the scrollview is scrolled to top and there is a tabbar above it? UITextView does this automatically but UIScrollView won't.Casque
Q
0

Swift 4 version (from here: https://mcmap.net/q/1322195/-uitextview-not-scrolling-in-tvos)

scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value:UITouchType.indirect.rawValue)]
Quadrate answered 19/2, 2018 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.