動畫頂端插入行我有標準的UITableView與自定義的UITableViewCell。我想要實現的是:在裏面的UITableView
每行都應該在顯示在TableView上時一次淡入。
但是,應注意每個新行應始終插入頂部,從而將先前存在的行向下推動1個單元 - 以獲得「推入堆棧」動畫。
這裏是我到現在爲止,這確實與香草褪色個體插入的,但在底部:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.alpha = 0
let delayBetweenRowInserts = 0.5 + Double(indexPath.row) * 1.0; //calculate delay
UIView.animateWithDuration(1, delay: delayBetweenRowInserts, options: .TransitionCurlUp, animations: {
cell.alpha = 1.0
}, completion: nil
)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = leaderboardTableView.dequeueReusableCellWithIdentifier(CUSTOM_CELL) as? CustomTableViewCell {
let playerName = Array(Games.leaderboard[indexPath.row].keys)[0]
let playerScore = Array(Games.leaderboard[indexPath.row].values)[0]
cell.configureCell(playerName, score: "\(playerScore)")
return cell
} else {
return UITableViewCell()
}
}
動機:我基本上都用盡所有的數據在我的數據源陣列一個去,即Games.leaderboard而不依賴於用戶的情況下,向下滾動他的屏幕尺寸太小,放不下的一切。這構成了我的應用程序用戶體驗中非常關鍵的一部分。
任何幫助,非常感謝!謝謝
P.S作爲替代方法,我嘗試使用beginUpdates().Top: 我試過使用beginUpdates()。在我看來,它不會改變動畫行的索引。我打電話startInsertingRows()
數據源後,已準備好
func startInsertingRows() {
var indexPaths = [NSIndexPath]()
for index in 0...Games.leaderboard.count-1 {
indexPaths.append(NSIndexPath(forItem: Games.leaderboard.count-1-index, inSection: 0))
}
leaderboardTableView.beginUpdates()
leaderboardTableView.insertRowsAtIndexPaths((indexPaths), withRowAnimation: .Top)
leaderboardTableView.endUpdates()
}
並不真正瞭解你的REQ,但如果你想推的動畫,你可以用'讓部分=的NSIndexSet(indexesInRange:NSMakeRange(0,self.tableView.numberOfSections))''然後self.tableView.reloadSections (節,withRowAnimation:.Automatic)'而不是'tableView.reloadData' – Tj3n
@ Tj3n根據我當前的代碼: -row插入動畫發生在第一行出現在表上並且後續行得到添加到底部。 -However,我想是最新的行,要始終在頂部插入即當前indexPath.row及以上行被推下來 - 有點像一個Facebook/Twitter的飼料更新,但有個別動畫 –
它還挺容易的不是它,有你試過'beginUpdate',添加對象到您的數據源,然後調用'insertRowAtIndexPath'和'endUpdate' – Tj3n