Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focus for UICollectionViewCells on tvOS

I'm new to tvOS. I have created UICollectionView using a XIB file in Objective-C. How can I focus UICollectionViewCell?

I have a label and an image view in the cell, and I want to focus both the label and the image view.

like image 238
IMakk Avatar asked Nov 23 '15 05:11

IMakk


1 Answers

UICollectionViewCell are not focus appearance by default, but you can achive this by adding one yourself.

- (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
    }
}

OR

If you just want to focus ImageView like scaling it up when collection view cell get focus you can do like this in awakeFromNib method

self.imageView.adjustsImageWhenAncestorFocused = YES;
self.clipToBounds = NO;
like image 174
Adnan Aftab Avatar answered Oct 13 '22 23:10

Adnan Aftab