Jenel Ejercito Myers Jenel Ejercito Myers - 8 months ago 47
iOS Question

Collection view cell animated tvOS

I am trying to animate a collection view cell, this is my code so far

- (void)collectionView:(UICollectionView *)collectionView didUpdateFocusInContext:(UICollectionViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator{

UICollectionViewCell *nextFocusedCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCell" forIndexPath:context.nextFocusedIndexPath];
UICollectionViewCell *previousFocusedCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCell" forIndexPath:context.previouslyFocusedIndexPath];
if (context.nextFocusedView) {
[coordinator addCoordinatedAnimations:^{
[nextFocusedCell setFrame: CGRectMake(3, 14, 300, 300)];
} completion:^{
// completion
} else if (context.previouslyFocusedView) {
[coordinator addCoordinatedAnimations:^{
[previousFocusedCell setFrame: CGRectMake(3, 14, 100, 100)];
} completion:^{
// completion

But my code is not working. I've read the documentation and it says to implement something like
if (self == contextFocusedView)...... but it has a warning saying that incompatible pointer View Controller to UIView. Could someone please tell me whats wrong with my code & how to fix it? Thanks!!


So I ended up figuring it out. I had a UIImage in my collectionView. One of the properties of a UIImage for tvOS is adjustsImageWhenAncestorFocused. So if you set this in your viewDidLoad like :

    _imageView.adjustsImageWhenAncestorFocused = Yes;

Alternatively, check the "Adjusts image when focused" box in your storyboard. this will focus the image. I have not tried it for labels. or any other elements that you can add in a collection View cell, but I'm sure there is something similar.

Happy programming guys! (: