1
我需要在UITableView中插入部分動畫來插入部分,但我需要從屏幕底部開始動畫。如何從屏幕底部設置動畫插入部分
而不是像默認的UITableViewRowAnimation
動畫之一。
這是動畫,我需要:
有什麼建議?
感謝
我需要在UITableView中插入部分動畫來插入部分,但我需要從屏幕底部開始動畫。如何從屏幕底部設置動畫插入部分
而不是像默認的UITableViewRowAnimation
動畫之一。
這是動畫,我需要:
有什麼建議?
感謝
我想通過一個簡單的解決方案來做到這一點。
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
如何