Search code examples
uiimageviewuicollectionviewtvos

tvOS collection view cell


I noticed you have to use .adjustsImageWhenAncestorFocused to 'pop' the collection view cell's image when focused. This has created a problem for me, without .adjustsImageWhenAncestorFocused the images are fine, but with that method, it crops my images on the top and bottom.

Did anyone run into this and solve it? I tried .clipsToBounds = true but that doesn't solve my problem.


Solution

  • You could make your UICollectionView bigger, or use this method to control the focus animation:

    let originalImageSize = CGSizeMake(100, 100)
    let focusedImageSize = CGSizeMake(120, 120)
    
    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
    coordinator.addCoordinatedAnimations({ [unowned self] in
        if self.focused {
            self.imageView.frame.size = focusedImageSize
        }
        else {
            self.imageView.frame.size = originalImageSize
        }
        }, completion: nil)
    }
    

    You need to add this code to your custom UICollectionViewCell class. Hope it helps.