【问题标题】:Focus engine not working on collection view cell焦点引擎不适用于集合视图单元
【发布时间】:2015-10-19 14:33:32
【问题描述】:

刚开始玩 tvOS,但我无法让焦点引擎在我的收藏视图上工作。焦点几乎适用于所有其他 UI 元素,例如按钮和表格视图,但不适用于集合视图。

我已尝试覆盖委托 canFocusItemAtIndexPath 并将单元格设置为 cell.camBecomeFocused(),但都不起作用。

谢谢大家

【问题讨论】:

    标签: swift tvos


    【解决方案1】:

    你应该看看 preferredFocusedView 方法。

    https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UIFocusEnvironment_Protocol/index.html#//apple_ref/occ/intfp/UIFocusEnvironment/preferredFocusedView

    您可以将其添加到您的集合视图单元格中,以指定当单元格获得焦点时哪个子视图应该获得焦点。例如:

    - (UIView *)preferredFocusedView
    {
        // In this case, there would be a UITextField hooked up as _myTextField_
        return self.myTextField;
    }
    

    现在,当 Collection View Cell 获得焦点时,在本例中,文本字段将获得焦点。

    【讨论】:

      【解决方案2】:

      我有同样的问题,我在重新加载时无法聚焦 UICollectionView。该解决方案解决了我的问题。 正如 Apple 工程师所说,默认情况下 UICollectionViewCells 没有任何焦点,但您的 imageView 可以设置 adjustsImageWhenAncestorFocused 为 YES 使焦点出现在 collectionViewCell 中。

      这里是代码。

      cell.imageView.adjustsImageWhenAncestorFocused  = true
      

      也可以参考这个链接。https://forums.developer.apple.com/message/56262#56262

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        • 2011-05-13
        • 2020-04-16
        • 1970-01-01
        相关资源
        最近更新 更多