ios - 在加载时在 Swift 中为 TableView 单元格设置动画(Up into TableView)

标签 ios swift uitableview

我设置了这段代码,以便它在显示时调用 tableview 单元格并为其设置动画。我如何设置它,以便它只对出现在 View 初始加载时的单元格进行动画处理?

提前致谢...

  var preventAnimation = Set<NSIndexPath>()

  func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    // 
    if !preventAnimation.contains(indexPath) {
        preventAnimation.insert(indexPath)
        let rotationTransform = CATransform3DTranslate(CATransform3DIdentity, 0, +600, 0)
        cell.layer.transform = rotationTransform
        UIView.animateWithDuration(0.6, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: .CurveEaseOut, animations: {
            cell.layer.transform = CATransform3DIdentity
            }, completion: nil)
    }
}

最佳答案

您可以只使用一个变量maxCellIndexAppeared 重新编码已出现的单元格的最大indexPath.row,这比使用一个集合包含所有indexPath 更好。

在initialize方法中将maxCellIndexAppeared设置为零,然后将其与单元格显示时的indexPath.row进行比较,如果当前单元格indexPath大于该变量则做你的动画,否则返回。

就像这样:

    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if maxCellIndexAppeared > indexPath.row {
           return
        }

        //here reset the current maximum index
        maxCellIndexAppeared = indexPath.row
        //And then do your animation
       ....do your animation.....
   }

关于ios - 在加载时在 Swift 中为 TableView 单元格设置动画(Up into TableView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37473890/

相关文章:

ios - 在 pageViewController 内的 tableView 上滑动以删除

ios - 为 UIAlertView 创建摇动动画

swift - 链接器命令失败,退出代码 1 : Google Maps

ios - UITableView 中的 UICollectionView 滚动时卡住

ios - 架构 armv7 的 undefined symbol : "_OBJC_CLASS_$_MPMusicPlayerController"

iOS 在 TableView 中创建空白部分

ios - 在表格 View 的特定单元格中创建文本字段

swift - 枚举的段错误

ios - tableView initwithframe 和 storyboard

ios - 标题对于 UIContextualAction 不可见(UITableView 滑动以删除 - iOS 11)