在 tvOS App 中支持指向性遥控

除了 Siri Remote,tvOS 还提供了对一系列使用触摸或按键界面的硬件与软件遥控的支持。如果你的 App 使用标准框架,如 UIKit 和 AVKit,tvOS 会自动处理遥控交互,以提供连贯且熟悉的体验。如果你的 App 包含定制界面元素或者媒体播放器,你仍然可以轻松为使用触摸和按键界面的硬件与软件遥控提供导览与基于内容的功能支持。方法如下:

探索 App 导览

在 Apple TV 上,人们会使用遥控器或游戏控制器在内容海报、App 或按键等界面元素间进行导览,被选中的项目会高光显示。高光显示的项目被称为 focusedin focus(聚焦)。UIKit 的焦点引擎控制 tvOS 上的聚焦与移动,听取由遥控或游戏控制器触发的焦点移动事件,并通知 App 提供相应内容。tvOS 的全部标准手势默认支持指向性遥控,你还可以在 App 中使用 UITapGestureRecognizer 这样的类,来为自定义手势提供支持。

About focus interactions for Apple TV

为指向性遥控采用自定义手势 如果你在 App 界面内支持控制特定动作的自定义手势,你可以添加 UITapGestureRecognizer,以映射一个明确的指向性事件。

// Gesture to handle directional pad down
let customGesture = UITapGestureRecognizer(target: self, action: #selector(specialAction))
customGesture.allowedPressTypes = [.downArrow]
view.addGestureRecognizer(customGesture)

UITapGestureRecognizer

Learn more about detecting gestures and button presses

Explore the App Programming Guide for tvOS

Providing Channel Navigation

MPRemoteCommandCenter

Becoming a now playable app

Remote command center events