分别为每一行插入动画Swift

时间:2015-09-07 11:29:26

标签: ios swift uitableview animation custom-cell

我插入新的部分(insertSections)以及其中的新行(insertRowsAtIndexPaths)。我为了withRowAnimation参数而使用这两个函数。

在堆栈社区的帮助下,我已经能够覆盖内置动画并使其更长 - 使用cellForRowAtIndexPaths

中的以下技巧
    if(storedarraysofindexes[indexPath.section].containsIndex(indexPath.row)){
        //for _ in storedarraysofindexes[indexPath.section]{

        for _ in storedarraysofindexes[indexPath.section]{
            cell.alpha = 0

        UIView.animateWithDuration(4.0, animations:  {() in
            cell.alpha = 1.0
            }, completion:{(Bool)  in
            self.storedarraysofindexes[indexPath.section].removeIndex(indexPath.row)
        })}}

我将每个部分的每个indexPath.row保存到NSMutableIndexSets数组中,并在应用效果后将其删除。

动画有效,但所有单元格都会立即插入。我希望这个动画分别适用于每个新插入的单元格。不幸的是,即使是循环(在代码中提到)也没有帮助我解决这个问题。

非常感谢任何见解。

更新

添加了包含在函数

中的insertRowsAtIndexPaths和insertSections的代码
func insertData(){

// step 1 - appending the array

my2darray.append(dataarray[option1]!)


// step 2 -generating a range of IndexPaths for the appended array values

     let insertedIndexPathRange = 0..<self.dataarray[self.option1]!.count + 1
     self.insertedIndexPaths = insertedIndexPathRange.map { NSIndexPath(forRow: $0, inSection: self.my2darray.count - 1) }



// step 3 - appending our NSMutableIndexSet with current indexes

     var update2 = NSMutableIndexSet ()

    for indexPathMe in insertedIndexPathRange{
        update2.addIndex(indexPathMe)
    }
    storedarraysofindexes += [update2]

// step 4 - inserting sections as well as rows

    self.tableView1.beginUpdates()
    self.tableView1.insertSections(NSIndexSet(index: self.my2darray.count - 1), withRowAnimation: .Fade)
    self.tableView1.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
    self.tableView1.endUpdates()
}

0 个答案:

没有答案
相关问题