ios - UITableViewCell 动画按钮约束

标签 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()
            })
        }
    }
 }

最佳答案

您需要获取给定indexPath处的单元格,而不是将其出队(因为此时它不会成​​为表格 View 的一部分。)

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

   }

关于ios - UITableViewCell 动画按钮约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42275708/

相关文章:

ios - 初始 VoiceOver 选择

ios - 迁移到 Twilio Voice 5.0(iOS 13、Xcode 11): Custom incoming call view controller, 拒绝来电问题

ios - uicollectionviewcell 内的 uitableview 的滚动问题

ios - TableView圆角和阴影

ios - UIScrollView:在 scrollViewDidScroll 中获得更好的 contentOffset 预测:

ios - 如何在 ObjectMapper 中映射 JSON 字典?

ios - 数字键盘保持打开状态但禁用所有按钮?

ios - 如何在不使用 contentOffset 的情况下检查 UITableView 中第一行隐藏了多少?

ios - 如何在 Swift 函数中返回泛型参数的默认值?

ios - 如何在导航栏后面显示图像?