我試圖構建我的tvOS UI看起來類似於Apple TV主屏幕。當您專注於應用程序時,會在後臺顯示更大的圖像。 (頂部貨架區域)。問題是,當我調用didUpdateFocusInContext方法時,背景圖像會像它應該那樣更改,但僅在瀏覽collectionviewcell時纔會更改。只要一個,我把重點放在標籤欄,應用程序崩潰與錯誤的:tvOS檢查當前是否聚焦ui元素是一個CollectionViewCell
Could not cast value of type 'UITabBarButton' to CustomCollectionViewCell'.
我想我只是不知道如何檢查是否已聚焦的UI元素是CustomCollectionViewCell。 以下是我有:
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
let cell: CustomCollectionViewCell = context.nextFocusedView as! CustomCollectionViewCell
let indexPath: NSIndexPath? = self.collectionView.indexPathForCell(cell)
mainImageView.image = UIImage(named: images[indexPath!.row])
}