gpt4 book ai didi

iOS TV 按钮菜单和图像

转载 作者:行者123 更新时间:2023-11-28 06:01:56 25 4
gpt4 key购买 nike

我开始了一个基本的 iOS TV 项目。正如您在图像中看到的,我已经创建了不同的系统按钮和一个图像对象。如果我在模拟器上尝试它,我可以从带有键盘的按钮移动,也可以使用电视 Remote 移动而无需任何代码。现在,每当我选择任何不同的按钮时,我都想更改图像。例如:如果我在 Button1 我想显示 Image1,如果我去 button6 我想显示 Image6 等等......但我找不到实现它的方法(我知道按钮、按钮状态、 socket 和 Action )...谁能帮我?我不会从零开始...我喜欢苹果系统按钮...谢谢

ViewController

最佳答案

在您的 View Controller 中实现以下方法来检测焦点的变化。然后只需查看 nextFocusedView 并根据需要更新图像。您可能想在按钮上设置 tag 属性并使用 switch 语句,但是有很多方法可以确定选择了哪个按钮。

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
guard let nextFocusedView = context.nextFocusedView,
let previouslyFocusedView = context.previouslyFocusedView else {
return
}

// Update image based on nextFocusedView
}

关于iOS TV 按钮菜单和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49386850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com