UITableViewCell动画按钮约束

时间:2017-02-16 13:45:03

标签: ios swift uitableview animation nslayoutconstraint

我有一个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()
            })
        }
    }
 }

1 个答案:

答案 0 :(得分:0)

您需要获取给定indexPath的单元格而不将其出列(因为此时它不会成​​为tableview的一部分。)

if let indexPath = indexPath {
   if let favoriteCell = favoriteStationsTableview.cellForRowAtIndexPath(indexPath) as? FavoriteCell
   {

   }
相关问题