Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 889
pascalbros Avatar asked Sep 16 '15 00:09

pascalbros


People also ask

What is UIScrollView?

UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.

What is Contentoffset?

The point at which the origin of the content view is offset from the origin of the scroll view.

What is Contentinsetadjustmentbehavior?

This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is UIScrollView.

How do I use scroll view in swift 5?

1. Add scrollView(1) in storyboard, add needed constraint to top/bottom/trailing/leading. 2. Then uncheck "Content Layout Guides" in Size inspector section for your scrollView.


1 Answers

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.

like image 75
Justin Voss Avatar answered Nov 11 '22 20:11

Justin Voss