UITableViewCell 动画按钮约束
UITableViewCell animate button constraint
我有一个 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
处获取单元格而不是将其出列(因为此时它不会成为表视图的一部分。)
if let indexPath = indexPath {
if let favoriteCell = favoriteStationsTableview.cellForRowAtIndexPath(indexPath) as? FavoriteCell
{
}
我有一个 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
处获取单元格而不是将其出列(因为此时它不会成为表视图的一部分。)
if let indexPath = indexPath {
if let favoriteCell = favoriteStationsTableview.cellForRowAtIndexPath(indexPath) as? FavoriteCell
{
}