我正在关注 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/