![](/img/trans.png)
[英]UITableview cells don't show up until you scroll. also with in main queue
[英]UITableView cells animation on scroll. Swift
這給出了類似於你想要的東西。 您可能需要對其進行調整或改進代碼片段。 您可以使用 tableView 的panGestureRecognizer屬性
tableView.panGestureRecognizer.addTarget(self, action: #selector(didPan(_:)))
使用此處理程序:
@objc func didPan(_ gesture: UIPanGestureRecognizer) {
guard gesture.state == .changed else { return }
let loc = gesture.location(in: tableView)
guard let touchedCellIndex = tableView.indexPathForRow(at: loc) else { return }
let n = tableView.numberOfRows(inSection: 0)
guard touchedCellIndex.row < n - 1 else { return }
if gesture.translation(in: tableView).y < 0 {
for (index, cell) in tableView.visibleCells.enumerated() {
guard let ip = tableView.indexPath(for: cell) else { return }
if ip.row > touchedCellIndex.row {
cell.transform = CGAffineTransform(translationX: 0.0, y: -gesture.velocity(in: tableView).y * 0.02 * tanh(CGFloat(index)))
UIView.animate(withDuration: 0.05 * Double(index), delay: 0.0) {
cell.transform = CGAffineTransform.identity
}
}
}
} else {
for (index, cell) in tableView.visibleCells.reversed().enumerated() {
guard let ip = tableView.indexPath(for: cell) else { return }
if ip.row < touchedCellIndex.row {
cell.transform = CGAffineTransform(translationX: 0.0, y: -gesture.velocity(in: tableView).y * 0.02 * tanh(CGFloat(index)))
UIView.animate(withDuration: 0.05 * Double(index), delay: 0.0) {
cell.transform = CGAffineTransform.identity
}
}
}
}
}
我相信您可以優化這種方法並使其更簡潔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.