我想在用戶觸摸時使用我的單元格進行翻轉動畫。當單元翻轉時,背面應顯示另一個圖像。UICollectionViewCell翻轉動畫
我已經解決了這個問題,把一個coverimage放在我的單元格內容之上,這個內容將被隱藏或者不被隱藏。
如何強制單元格執行翻轉動畫?我只能使它重新加載單元格,但這有副作用。
如何強制翻轉動畫,並在轉動180度時更改單元格的狀態?
這裏是我的UICollectionViewCell內的代碼包含動畫:
func makeImageVisible(visible:Bool, animated: Bool){
if(animated){
UIView.transitionWithView(self.contentView, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromLeft, animations: {() -> Void in
self.coverImageView.hidden = visible
}, completion: nil)
}
else{
self.coverImageView.hidden = visible
}
}
細胞中包含了由coverimage覆蓋的一些看法。取決於隱藏或不隱藏的狀態。
這裏是我的cellForIndexPath法:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MemoryGameCell", forIndexPath: indexPath) as! MemoryGameCell
cell.setImage(self.image!)
cell.makeImageVisibile(self.imageIsVisible(indexPath), animated: self.imageIsTemporaryVisible(indexPath))
return cell
}
如果電池被觸動我把它放在visiblecells陣中並重新加載的CollectionView。我直接調用makeImageVisible來重試加載collectionview,但沒有任何反應。 任何想法可能是什麼問題?
只需在UITableViewCell中有一個子視圖。在didSelectRow上使用 + transitionWithView:duration:options:animations:completion:來在子視圖上提供動畫。作爲一個選項,傳遞TransitionFlipFromBottom並用動畫塊中的新視圖替換舊視圖。 – TheCodingArt
您也可以使用CATransform圖層進行自定義UIAnimation。只需旋轉視圖圖層的一半(視圖的y軸朝向屏幕以使視圖不可見),然後用新視圖換出視圖並適當旋轉。 – TheCodingArt
我編輯了我的帖子並添加了我到目前爲止的代碼。對不起,我起初寫了TrableViewCell,但意思是CollectionviewCell。 – netshark1000