我有一个 UITableView 可以检测从左到右的滑动。我想在用户通过更改宽度约束常数进行滑动时显示删除按钮。但无论我尝试做什么,按钮都不会产生动画或改变宽度。我可以让按钮显示约束更改的唯一方法是重新加载行。
这就是我现在所拥有的。我看到的每个答案都包含这种动画约束的方法。
func TableViewSwipeRight(gesture: UIGestureRecognizer)
{
let point = gesture.location(in: favoriteStationsTableview)
let indexPath = favoriteStationsTableview.indexPathForRow(at: point)
if let indexPath = indexPath {
if let favoriteCell = favoriteStationsTableview.dequeueReusableCell(withIdentifier: FavoriteCell.GetReuseId(), for: indexPath) as? FavoriteCell {
self.view.layoutIfNeeded()
favoriteCell.deleteBtnConstraint.constant = 50
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
})
}
}
}
最佳答案
您需要获取给定indexPath
处的单元格,而不是将其出队(因为此时它不会成为表格 View 的一部分。)
if let indexPath = indexPath {
if let favoriteCell = favoriteStationsTableview.cellForRowAtIndexPath(indexPath) as? FavoriteCell
{
}
关于ios - UITableViewCell 动画按钮约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42275708/