0
誰かがこの問題を助けてくれることを願っています。以下は私のtvOSアプリのスクリーンショットです:コレクションビューのセル間でフォーカスを切り替えるときにUI要素を更新しようとしています
です。私は二つのことを行うにしようとしています
:
ユーザーがスクロールダウンし、そのリモコンのを、collectionViewの2番目の項目は自動的に焦点を当てになります。私は最初の項目が代わりに焦点を合わせるようにする必要があります。
コレクションビュー内のアイテム間で手動でフォーカスを移動すると、画面の中央セクションのUI要素を個別に押したり選択したりする必要がなくなります。ここで
は私のコードは、この画面のために、これまでです:
import UIKit
// Global variable
internal let g_CR1 = "channel_cell_01"
class DashboardVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
// outlets
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var lblChannelName: UILabel!
@IBOutlet weak var imgChannelLogo: UIImageView!
@IBOutlet weak var txtChannelDescription: UITextView!
// variables
var staticData: [Channel] = []
override func viewDidLoad() {
super.viewDidLoad()
// sample channels
initializeSampleData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - CollectionView Callbacks
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return staticData.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// Get or make a cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: g_CR1, for: indexPath) as! CollectionViewCell
// Configure
cell.imgView.backgroundColor = UIColor.black
cell.imgView.image = staticData[indexPath.row].chLogo
// Return.
return cell
}
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return true
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let currentChannel = staticData[indexPath.row]
DispatchQueue.main.async {
self.lblChannelName.text = currentChannel.chName
self.imgChannelLogo.image = currentChannel.chLogo
self.txtChannelDescription.text = currentChannel.chDescription
}
}
}