uitableview - swift 中的 TableViewCell 动画

标签 uitableview animation swift

我正在关注 THIS教程并使用此代码实现该动画:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1)
    UIView.animateWithDuration(0.25, animations: {
        cell.layer.transform = CATransform3DMakeScale(1,1,1)
    })

}

但是我想更新这个单元格动画中的一些东西,比如当我滚动到 tableView 时,单元格在开始时像 (0.1,0.1,1) 一样小,之后它像 一样缩放(1,1,1) 但我想应用类似气泡类型的效果,因为它在开始时很小,之后它以其原始比例出现,如 (1,1,1) 和一个是缩放,然后又回到原始比例,如 (1,1,1)

请指导我如何实现该动画?

编辑:

我试过了,但不是很流畅,也不是我想要的。

    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1)
    UIView.animateWithDuration(0.3, animations: {
        cell.layer.transform = CATransform3DMakeScale(1,1,1)
    })
    UIView.animateWithDuration(1, animations: {
        cell.layer.transform = CATransform3DMakeScale(2,2,2)
    })
    UIView.animateWithDuration(0.3, animations: {
        cell.layer.transform = CATransform3DMakeScale(1,1,1)
    })

}

最佳答案

您需要的是缓出后退动画。有关更多信息,请查看 http://easings.net

您可以使用此库制作参数化动画 https://github.com/jjackson26/JMJParametricAnimation/tree/master/JMJParametricAnimationDemo

目前,您尝试做的效果可以使用下面的代码大致完成。你必须一个接一个地做缩放动画。您所做的方式使所有动画一起开始。
完成 block 中添加下一个动画代码会在动画之后启动它。您可以进一步调整时间以获得所需的粗略效果。

    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1)
    UIView.animateWithDuration(0.3, animations: {
        cell.layer.transform = CATransform3DMakeScale(1.05,1.05,1)
        },completion: { finished in
            UIView.animateWithDuration(0.1, animations: {
                cell.layer.transform = CATransform3DMakeScale(1,1,1)
            })
    })

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

相关文章:

ios - 如何在 iOS 的 Tableview 的第一部分中设置数组数据第一个值,在 tableview 的第二部分中设置剩余的数组数据值?

java - LibGDX 访问另一个类中的动画?

扩展中的 Swift Animate 约束

ios - 如何在 Swift 中以编程方式创建约束?

swift - 删除 MKAnnotation 后如何更新 UserDefaults?

arrays - 当仅按下一个 Swift 时,阵列中的多个开关被激活

UINavigationController 中的 UITableView 旋转后进入导航栏

iphone - 如何添加pull tableview up来刷新uitableview里面的数据

ios - Swift 获取 tableview 数组计数并将其放置在 textview

python - 使用 matplotlib 'format "rgba 的动画“不支持”