Ios UICollectionViewCell翻转动画不工作

Ios UICollectionViewCell翻转动画不工作,ios,swift,uicollectionviewcell,uiviewanimation,Ios,Swift,Uicollectionviewcell,Uiviewanimation,我正在尝试在UICollectionViewCell上实现翻转动画。下面的代码不起作用(根本没有动画),所以我请求帮助 我的自定义单元格有一个内容视图,包含两个UIView(FrontsideView和BacksideView)。在它们里面,我有一些带有约束的标签 轻敲单元格时应执行代码(代理工作正常)。这是我的自定义单元格: class ProjectCVCell:UICollectionViewCell{ @IBVAR前端视图:UIView! @IBVAR背面视图:UIView! func

我正在尝试在UICollectionViewCell上实现翻转动画。下面的代码不起作用(根本没有动画),所以我请求帮助

我的自定义单元格有一个内容视图,包含两个UIView(FrontsideView和BacksideView)。在它们里面,我有一些带有约束的标签

轻敲单元格时应执行代码(代理工作正常)。这是我的自定义单元格:

class ProjectCVCell:UICollectionViewCell{
@IBVAR前端视图:UIView!
@IBVAR背面视图:UIView!
func动画(){
让transitionOptions:UIView.AnimationOptions=[.transitionFlipFromRight]
UIView.transition(带有:self.contentView,持续时间:0.5,选项:transitionOptions,动画:{
self.frontsideView.ishiden=!self.frontsideView.ishiden
self.backsideView.ishiden=!self.backsideView.ishiden
},完成日期:{
完成于
} )
}
}
这是didSelectItemAt函数:

func collectionView(collectionView:UICollectionView,didSelectItemAt indepath:indepath){
guard let cell=collectionView.DequeueReuseAbleCell(带有ReuseIdentifier:“cell”,for:indexPath)作为?ProjectCVCell else{return}
cell.flipAnimation()
}
我做错了什么?

你可以试试

UIView.transition(with: self.contentView, duration: 0.5, options: transitionOptions, animations: {
        self.frontsideView.alpha = self.frontsideView.alpha == 1.0 ? 0.0 : 1.0
        self.backsideView.alpha = self.backsideView.alpha == 1.0 ? 0.0 : 1.0
}, completion: { _ in
} )
改变

guard let cell = collectionView.cellForItem(at:indexPath) as? ProjectCVCell else { return }

您应该需要使用
collectionView.cellForItem(at:indexPath)作为?ProjectCVCell else{return}
在didSelect内。
dequeueReusableCell
不允许在
cellForItemAt
外调用此方法。最后一个方法成功了。但它是cellForItem,因为它是@Raja Kishan提到的集合视图。