【发布时间】:2016-07-05 15:37:30
【问题描述】:
我做小部件。我需要用动画改变单元格的高度。当点击“显示更多”去额外的控制。 enter image description here
我写了这段代码
tableView.beginUpdates()
showModes(alpha: 1, duration: 0.2, delay: 0.1)
tableView.endUpdates()
func showModes(alpha: CGFloat, duration: CGFloat, delay: CGFloat) {
if tableView.numberOfRows(inSection: 0) != 0 {
for i in 0...tableView.numberOfRows(inSection: 0)-1 {
let indexPath = IndexPath(row: i, section: 0)
if let cell = tableView.cellForRow(at: indexPath) as? WidgetCell {
UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay) ,animations: {
if alpha == 0 {
cell.favoriteConstraint.constant = -45
} else {
cell.favoriteConstraint.constant = 10
}
cell.favoriteMode.alpha = alpha
self.tableView.layoutIfNeeded()
})
}
}
}
}
但它并不顺利。它剧烈地上下抽搐。如何让它顺利运行,例如,在 Apple 的天气小部件中?
【问题讨论】:
标签: xcode swift uitableview animation today-extension