swift - tableView 中的约束动画问题

标签 swift uitableview animation

当我使用 tapGesture 时,我希望 likeButton 从 View 外部飞入,限制为 2。当我点击时,likeButton 会出现在我需要的位置,但没有动画可以将其到达那里。在动画方面还有很多东西需要学习。有什么帮助,谢谢!!约束当前设置为刚好在 View 外部 -80。

@objc func handleTapGesture(gestureReconizer: UITapGestureRecognizer) {
    let p = gestureReconizer.location(in: messageTableView)

    let indexPath = messageTableView.indexPathForRow(at: p)

    let cellAnimate = messageTableView.dequeueReusableCell(withIdentifier: "customMessageCell", for: indexPath!) as! CustomMessageCell
            UIView.animate(withDuration: 0.5) {

                cellAnimate.likeButtonContraint.constant = 2
                cellAnimate.layoutIfNeeded()
            }

}

最佳答案

而不是

let cellAnimate = messageTableView.dequeueReusableCell(withIdentifier: "customMessageCell", for: indexPath!) as! CustomMessageCell

let cellAnimate = messageTableView.cellForRow(at:indexPath!) as! CustomMessageCell

由于 dequeueReusableCell 返回另一个单元格以供重用,而不是您期望的位于您提供的 indexPath 处的单元格

//

let cellAnimate = messageTableView.cellForRow(at:indexPath!) as! CustomMessageCell
cellAnimate.likeButtonContraint.constant = 2
UIView.animate(withDuration: 0.5) {
   cellAnimate.layoutIfNeeded()
}

关于swift - tableView 中的约束动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51564330/

相关文章:

jquery 在播放 css 动画后删除类?

swift - 我正在尝试快速创建 UIImageView 的子类以添加一个简单的计数器

Java 帧动画损害性能

Ios swift TableView Cell Label LineBreak 不工作......

带有 JSON 数组的 iOS swift tableView header

ios - 如何从 json 调用评级 View 并在我的 TableView 中显示评级

ios - 在 UITableViewCell 中使用 Timer 在 UILabel 中设置时间

animation - QML 定时器与转换相结合

ios - Swift:如何更新可变形对象

objective-c - 如何将 Objective-C 文件添加/导入到 Swift 应用程序