2013-01-05 10 views
0

在我的應用程序中有一些顯示一些信息的UICollectionViewCells。如何將視圖放在UICollectionViewCell的背面

當用戶點擊其中的一個按鈕,我翻轉抽頭細胞與這一塊的代碼:將所述細胞翻轉

UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath]; 

[UIView animateWithDuration:1.0 
         delay:0 
        options:(UIViewAnimationOptionAllowUserInteraction) 
       animations:^ 
       { 
        NSLog(@"starting animation"); 

        [UIView transitionFromView:cell.contentView 
             toView:cell.contentView 
             duration:.5 
             options:UIViewAnimationOptionTransitionFlipFromRight 
            completion:nil]; 
       } 
       completion:^(BOOL finished) 
       { 
        NSLog(@"animation end"); 
       } 
]; 

後(這是不正確的),細胞是完全地白。

有兩個問題是: - 爲什麼翻轉後單元格變白。由於fromView等於toView,它不應該顯示原始信息嗎? - 在單元格背面顯示不同內容的最佳方式是什麼?我想UICollectionViewCell沒有什麼聯繫cell.contentViewBack ...

回答

1

你現在可能有這樣的,但是,

不知道這是否是「最佳」的方式做到這一點,我得到這個工作通過創建一個自定義的UICollectionViewCell,在自定義單元格中有2個UIImageViews,並在動畫中定位這些視圖(這隻適用於你,如果這就是你想要的所有單元格 - 可能有幫助,可能不會,任何人)

創建新的UICollectionViewCell類(我的名爲CardCVCell) 在CardCVCell.h中放入你的UIImageView插座

@property (strong, nonatomic) IBOutlet UIImageView *cardImage; 
@property (strong, nonatomic) IBOutlet UIImageView *cardBackImage; 

我使用了故事板 - 在那裏,我在'CardCVCell'中輸入了我的場景中集合視圖中單元格上的自定義類。

在爲那場戲我中有你有上面的代碼我的視圖控制器,但是我用的UIImageViews在過渡的意見,自定義單元格(注意,您必須將UICollectionViewCell投射到您的自定義類

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
// animate the cell user tapped on 
CardCVCell *cell = (CardCVCell *)[collectionView cellForItemAtIndexPath:indexPath]; 

     [UIView transitionFromView:cell.cardBackImage 
          toView:cell.cardImage 
          duration:.5 
          options:UIViewAnimationOptionTransitionFlipFromRight 
         completion:^(BOOL finished) 
      { 
       if (finished) { 
        NSLog(@"animation end"); 
       } 

      } 
    ];  
} 

我希望這可以幫助別人,如果沒有你,如果我能幫助讓我知道。

歡呼

+0

這正是我所需要的一個反向的紙牌遊戲。謝謝craigk,我投你一票:) – 2013-05-13 13:32:48

+0

這是很好的解決方案。但我有一個問題。你怎麼知道現在哪個視圖在前面? (必須創建一些數據結構來保持狀態?) –

+0

UIViewAnimationOptions.ShowHideTransitionViews是關鍵。 –

相關問題