AppleTV Focusing CollectionView elements in TableView

1k views Asked by At

I'm building an app for AppleTV which has a UITableView. I made a custom cell for it, which has a UILabel and a UICollectionView. Is there a way to make both the label and the elements of the collection view focusable? I tried making both table view's canFocusRowAt and collection view's canFocusItemAt to return true, but its not working. Any ideas?

1

There are 1 answers

0
Santosh On

UICollectionViewCell/UITableViewCell are not focus appearance by default, we need to override the below function in subclass of UICollectionViewCell/UITableViewCell and do the focus settings.

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    if isFocused {
        //Apply your focused appearance
    }else{
        //Apply normal appearance
    }
}

Also if you have just a UIImageView in your collectionViewCell then you can just do below in your awakeFromNib:

myImageView.adjustsImageWhenAncestorFocused = true
clipsToBounds = false