2015-09-26 56 views
8

我正在使用iOS 9 Storyboards創建tvOS應用程序。tvOS:在UICollectionViewCell上創建視差效果

該應用程序有一個UICollectionView。我已在我的Assets.xcassets集合中定義了包含Front,Middle和Back資產的Apple TV圖像堆棧。

當用戶突出顯示UICollectionViewCell時,我想要有一個類似於應用程序圖標的「突出顯示」效果,用戶可以在Siri遙控器上「旋轉」他們的手指以暴露視差效果並閃耀。

有沒有人有這方面的經驗?

+2

FYI有對蘋果的網站上視差預覽:https://developer.apple.com/tvos/download/有很多在YouTube上的如何使用這一點。 – Jacksonkr

+0

我們創建了控件和擴展,可以用來輕鬆添加視差效果到任何UIView github.com/PGSSoft/ParallaxView –

回答

13

剛剛找到答案。希望這可以幫助別人:

- (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; 
} 
+0

精彩!!!!!!!!!!!! – SpaceDog

+0

一般情況下,我會建議[cell.contentView addsubView:ImageView],以防你想利用兩個UICollectionViewCell backgroundView屬性。 –