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.

4

2 回答 2

25

您可以配置滚动视图的内置平移手势以识别 Siri Remote 上的触摸。它不会自动执行此操作,因为通常 tvOS 上的滚动视图不会通过触摸直接滚动:它们会随着焦点在滚动视图内的视图之间移动而自动滚动。

如果您真的希望滚动视图直接从触摸移动,您需要添加UITouchTypeIndirectallowedTouchTypes滚动视图的panGestureRecognizer

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

您还需要确保滚动视图本身是焦点视图,或者是焦点视图的父级,因为来自遥控器的所有触摸都将从焦点视图的中心开始:您需要确保滚动视图正在对事件进行命中测试以使其正常工作。

缩放不起作用,因为 Siri Remote 一次只能识别一个触摸,因此您无法对其进行捏合手势。

于 2015-09-16T02:29:19.407 回答
0

Swift 4 版本(来自这里:https ://stackoverflow.com/a/41000183/945247 )

scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value:UITouchType.indirect.rawValue)]
于 2018-02-19T14:33:06.233 回答