在Apple TV上使用多个控件管理焦点 [英] Manage Focus with multiple controls on Apple TV

查看:167
本文介绍了在Apple TV上使用多个控件管理焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的屏幕上有多个控件.在右上角有一个收集视图,然后在左中间有一个按钮,除了按钮之外,我还有另一个收集视图.请参考附件图像

I have multiple controls on my screen. A collection view on right-top, then a button at left-center and besides the button, i have another collection view. Please refer the attached image for it

我能够将焦点从按钮移到底部集合视图,反之亦然.我已经为以下内容创建了焦点指南:

I am able to move the focus from button to bottom collection view and vice versa. I have created a focus guide for the same as below:


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

        self.focusGuide.topAnchor.constraintEqualToAnchor(collectionViewHeader.topAnchor).active = true
        self.focusGuide.bottomAnchor.constraintEqualToAnchor(collectionViewBottom.topAnchor).active = true
        self.focusGuide.leadingAnchor.constraintEqualToAnchor(collectionViewBottom.leadingAnchor).active = true
        self.focusGuide.widthAnchor.constraintEqualToAnchor(collectionViewBottom.widthAnchor).active = true

在didUpdateFocusInContext:中,我写了:

and in didUpdateFocusInContext: , I have write :


    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)

        guard let nextFocusedView = context.nextFocusedView else { return }

            if(nextFocusedView .isKindOfClass(bottomCell)) {
            self.focusGuide.preferredFocusedView = self.btn
        } else {
            self.focusGuide.preferredFocusedView = self.collectionViewBottom
        }
    }

但是,我无法将焦点从按钮移到顶部收藏夹视图.为此,我可能需要多个焦点指南,但是我不知道该怎么办.谁可以帮我这个事?

But, I am not able to move focus from button to top collection view. I may need multiple focus guide for this, but I do not know what should come there. Can anyone help me on this?

谢谢

推荐答案

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

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.

这篇关于在Apple TV上使用多个控件管理焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆