Dav*_*son 5 animation uitableview custom-cell ios swift
我插入新的section(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)
})}}
Run Code Online (Sandbox Code Playgroud)
我将每个部分的每个indexPath.row保存到一个数组中,NSMutableIndexSets并在应用效果后将其删除.
动画有效,但所有单元格都会立即插入.我希望这个动画分别适用于每个新插入的单元格.不幸的是,即使对于循环(在代码中提到)也没有帮助我解决这个问题.
任何见解都非常感谢.
UPDATE
添加了包含在函数中的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()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
660 次 |
| 最近记录: |