且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Apple TV上使用多个控件管理焦点

更新时间:2023-12-03 20:48:40

只需在按钮上方和顶部集合视图的左侧插入焦点指南,即可将焦点重定向到顶部集合视图:

Just insert a focus guide above the button and to the left of the top collection view, redirecting focus to the top collection view:

 focusGuide.preferredFocusedView = self.topView
    self.view.addLayoutGuide(focusGuide)

    self.focusGuide.topAnchor.constraintEqualToAnchor(topView.topAnchor).active = true
    self.focusGuide.bottomAnchor.constraintEqualToAnchor(topView.bottomAnchor).active = true
    self.focusGuide.leadingAnchor.constraintEqualToAnchor(btn.leadingAnchor).active = true
    self.focusGuide.trailingAnchor.constraintEqualToAnchor(btn.trailingAnchor).active = true

您可能还希望在按钮右侧和顶部收藏视图下方插入焦点指南,以便从顶部行向下导航将焦点重定向到按钮而不是底部行.

You may also want to insert a focus guide to the right of the button and below the top collection view so that navigating down from the top row redirects focus to the button instead of to the bottom row.