Dha*_*esh 8 animation uitableview swift
我正在按照本教程使用以下代码实现该动画:
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)
})
}
Run Code Online (Sandbox Code Playgroud)
但是我想在这个单元格动画中更新一些内容,比如当我滚动到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)
})
}
Run Code Online (Sandbox Code Playgroud)
rak*_*hbs 21
你需要的是一个轻松的动画.有关更多信息,请访问http://easings.net
您可以使用此库制作参数化动画https://github.com/jjackson26/JMJParametricAnimation/tree/master/JMJParametricAnimationDemo
目前,您尝试做的效果可以使用下面的代码大致完成.你必须一个接一个地进行缩放动画.你的方式使所有的动画一起开始.
在完成块中添加下一个动画代码会在动画后启动它.您可以进一步调整时间以获得所需的粗略效果.
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)
})
})
Run Code Online (Sandbox Code Playgroud)
Alf*_*lfi 15
斯威夫特4
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
UIView.animate(withDuration: 0.4) {
cell.transform = CGAffineTransform.identity
}
}
Run Code Online (Sandbox Code Playgroud)
Swift 3版本就像魅力!
cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1)
UIView.animate(withDuration: 0.3, animations: {
cell.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1)
},completion: { finished in
UIView.animate(withDuration: 0.1, animations: {
cell.layer.transform = CATransform3DMakeScale(1, 1, 1)
})
})
Run Code Online (Sandbox Code Playgroud)