如果不使用 Delay Run 就會導致無限卡住在第一個焦點位置。
使用 Delay 就會循環在第一張圖和選中的焦點來回切換。
.focused($Focused)
.onChange(of: Focused) { newValue in
if newValue {
print("...", item.recentTitle)
DelayRun.task(delay: 0.6) {
appStatus.MainViewBackgroundURL = backgroundImageURL?.description ?? ""
}
}
}
不知道。最後使用 UIKit 方案解決。
func collectionView(_ collectionView: UICollectionView, didUpdateFocusIn context: UICollectionViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if let indexPath = context.nextFocusedIndexPath {
RecentBackground.setMainBackground(byIndex: indexPath.row)
}
}