Search code examples
uicollectionviewswift3scaleuicollectionviewcelltvos

tvos elevate collection view cell on focus


I want to increase the size of an UICollectionViewCell focused inside the collection view.

How can I increase the size of an UICollectionViewCell when it's focused? I couldn't do it with CGAffine, I tried this:

cellChosen.transform = CGAffineTransform(scaleX: 2, y: 2)

but it didn't work. Did I do it wrongly?

There is also an effect on the UIImageView called adjustImageWhenAncestorFocused that is quite cool. Is it possible to use it on the cell ?

IMPORTANT: I'm using swift 3 and the cell has an UILabel and a UIImageView.


Solution

  • You need to use transform in didUpdateFocusInContext. For example

    - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
    {
        if (self.focused)
        {
            // Apply focused appearence,
            // e.g scale both of them using transform or apply background color 
        }
        else
        {
           // Apply normal appearance
        }
    }