很难弄清楚这一点- Gif of the issue
我尝试过根据需要调用布局,但这似乎无济于事。
这是我的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! BrandTableViewCell
tableView.layoutIfNeeded()
if openCellIndexPath == indexPath && openCellIndexPath != nil { //User clicks an already open cell
UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping:0.7,
initialSpringVelocity:0.0, options: [.transitionCrossDissolve], animations: {
//tableView.performBatchUpdates or begin/end updates
tableView.performBatchUpdates({self.openCellIndexPath = nil; tableView.layoutIfNeeded()} , completion: nil)
})
}
else { //User clicks a cell that is not open
tableView.layoutIfNeeded()
UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping:0.7,
initialSpringVelocity:0.0, options: [.transitionCrossDissolve], animations: {
//tableView.performBatchUpdates or begin/end updates
tableView.performBatchUpdates({self.openCellIndexPath = indexPath; tableView.layoutIfNeeded()} , completion: nil)
})
}
}
感谢您的帮助。