【问题标题】:AppleTV Focusing CollectionView elements in TableViewAppleTV 在 TableView 中聚焦 CollectionView 元素
【发布时间】:2016-11-18 15:07:20
【问题描述】:

我正在为具有 UITableView 的 AppleTV 构建应用程序。我为它制作了一个自定义单元格,它有一个 UILabel 和一个 UICollectionView。有没有办法使集合视图的标签和元素都具有焦点?我尝试让表视图的 canFocusRowAt 和集合视图的 canFocusItemAt 都返回 true,但它不起作用。有什么想法吗?

【问题讨论】:

    标签: swift apple-tv focus-engine


    【解决方案1】:

    UICollectionViewCell/UITableViewCell默认不显示焦点,我们需要覆盖UICollectionViewCell/UITableViewCellsubclass中的以下函数并进行焦点设置。

    override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        if isFocused {
            //Apply your focused appearance
        }else{
            //Apply normal appearance
        }
    }
    

    此外,如果您的collectionViewCell 中只有一个UIImageView,那么您可以在您的awakeFromNib 中执行以下操作:

    myImageView.adjustsImageWhenAncestorFocused = true
    clipsToBounds = false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 2014-04-09
      • 1970-01-01
      • 2012-02-27
      相关资源
      最近更新 更多