答案 0 :(得分:3)
我想通过一个简单的解决方案来解决这个问题。
public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if shouldAnimate {
cell.alpha = 0
let transform = CATransform3DTranslate(CATransform3DIdentity, 0, UIScreen.main.bounds.height, 0)
cell.layer.transform = transform
UIView.animate(withDuration: 0.5, animations: {
cell.alpha = 1
cell.layer.transform = CATransform3DIdentity
})
}
}
public func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if shouldAnimate {
view.alpha = 0
let transform = CATransform3DTranslate(CATransform3DIdentity, 0, UIScreen.main.bounds.height, 0)
view.layer.transform = transform
UIView.animate(withDuration: 0.5, animations: {
view.alpha = 1
view.layer.transform = CATransform3DIdentity
})
}
}
public func addSections(sections: IndexSet) {
shouldAnimate = true
CATransaction.begin()
CATransaction.setCompletionBlock({ self.shouldAnimate = false })
tableView.beginUpdates()
tableView.insertSections(sections, with: .top)
tableView.endUpdates()
tableView.scrollToRow(at: IndexPath(row: 0, section: 1), at: .top, animated: true)
CATransaction.commit()
}
所以willDisplay cell/header
从屏幕底部处理动画。
shouldAnimate
在完成insertSection
答案 1 :(得分:0)
怎么样