IMakk IMakk - 6 months ago 214
Objective-C Question

Focus UIcollectionView Cell TvOS

i'm new to tvos. I have created UIcollectionview using xib file in objective-c. how can i focus UIcollectionview cell.

i have label and imageview in collectionview cell. and i want to focus both label and imageview..

thanks in advance

C_X C_X
Answer

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;
Comments