ios - UICollectionViewCell 翻转动画

标签 ios uitableview

当用户触摸我的单元格时,我希望有一个翻转动画。翻转单元格时,背面应显示另一幅图像。

我已经通过在我的单元格内容上方放置一个封面图像来解决它,该封面图像将被隐藏或不隐藏。

如何强制单元格执行翻转动画?我只能通过重新加载单元使其工作,但这有副作用。

如何强制翻转动画并在翻转 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/

相关文章:

ios - UISegmentedControl 确定动态 UITableView 的内容

ios - 为什么我的 UITableViews 在以编程方式添加时在 y 轴上放错了位置?

ios - 如何在 Swift 中使用 PFImageView?

ios - 如何选择要使用UICollectionView预取的项目数?

iphone - Apple 的 Reachability 源代码中存在严重错误? (本地 WiFi 的可达性)

iphone - 如何使用此代码在 iCarousel 中加载多个图像?

ios - SnapKit 和动态 UITableViewCell 布局不正确

swift - 在静态 UITableViewController 之上的 UIView

ios - UITableViewCell 的条件背景色

ios - 导航到同一屏幕,但来自两个不同的 View Controller