当用户触摸我的单元格时,我希望有一个翻转动画。翻转单元格时,背面应显示另一幅图像。
我已经通过在我的单元格内容上方放置一个封面图像来解决它,该封面图像将被隐藏或不隐藏。
如何强制单元格执行翻转动画?我只能通过重新加载单元使其工作,但这有副作用。
如何强制翻转动画并在翻转 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
}
}
该单元格包含一些被封面图像覆盖的 View 。封面图像是否隐藏取决于状态。
这是我的 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-array 并重新加载 collectionview。我在没有通过直接调用 makeImageVisible 重新加载 collectionview 的情况下进行了尝试,但是没有任何反应。 任何想法可能是什么问题?
最佳答案
您可以在 UITableView 的 didSelectRowAtIndexPath 委托(delegate)方法上做一个 UIView 动画。这是您应该调用的方法:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
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
} }
关于ios - UICollectionViewCell 翻转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31211963/