Search code examples
objective-ctvos

tvOS: Creating parallax effect on UICollectionViewCell


I'm using iOS 9 Storyboards to create a tvOS app.

The app has a UICollectionView. I've defined an Apple TV image stack that contains a Front, Middle and Back asset in my Assets.xcassets collection.

When a user highlights a UICollectionViewCell, I'd like to have a have a 'highlight' effect similar to what the app icon has, where a user can 'circle' their finger on the Siri remote to expose the parallax effect and shine.

Does anyone have any experience with this?


Solution

  • Just found an answer. Hope this helps someone else:

    - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CameraCell" forIndexPath:indexPath];
    
        UIImage *image = [_cameras objectAtIndex:indexPath.row];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.userInteractionEnabled = YES;
        imageView.adjustsImageWhenAncestorFocused = YES;
        imageView.frame = CGRectMake(0, 0, 853, 560);
        [cell addSubview:imageView];
    
        return cell;
    }