Animate/zoom tvOS 中的聚焦自定义视图

Animate/zoom a focused custom view in tvOS

我的 tvOS 应用中有一个自定义 UICollectionViewCell。它有一个 UIImageView 和一些 UILabel 。我可以毫无问题地通过实施 UIFocusEnvironment 协议来使单元格聚焦,但我不知道如何为我的自定义单元格提供聚焦外观。 (提升和响应用户在触摸板上的移动)。

我知道 UIImageViewadjustsImageWhenAncestorFocused 属性,但这只会提升我单元格中的图像,而不是整个单元格。

有没有办法让 tvOS 将(看似)标准焦点 appearance/behavior 应用到我的自定义视图,还是我必须手动完成这一切?

提前致谢。

tvOS 12.0+ 中的更新: 查看 类 Apple 在 TVUIKit 中提供的新功能!您现在可以制作具有这种聚焦行为的自定义视图!

————

我在 Apple 开发者论坛上问过同样的问题。苹果工作人员回答:

For custom views you'll have to implement the focus appearance yourself. In the focus update method you can do things like apply a transform and use the UIMotionAffect API.

- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
    if (context.nextFocusedView == self) {
       // handle focus appearance changes
    }
    else {
       // handle unfocused appearance changes
    }
}

我认为制作一个 UIView 扩展能够将相同的行为应用于任何自定义视图会很有帮助。

也许他们希望我们实现更有趣的方式来向用户显示焦点?这是仅对 UIImageView 轻松启用此功能的一个很好的理由(更不用说此行为还在 UIImageView 上添加了模拟光,这很漂亮,但可能只对图像有意义)。