在我的应用程序中,我需要一些动画,但如果它已经设置了动画,则不需要持续时间。但我的问题是它会自动添加持续时间。
在这里你可以看到 2 个函数,第二个没有持续时间但它确实有持续时间(可能从 1 秒开始),第一个函数有持续时间(它应该有并且没关系)但它不是 0.6 秒因为如果我将它设置为 30,它的动画效果仍然非常快。
我做错了什么,提前致谢!
func openMessage() {
UIView.animate(withDuration: 0.6, delay: 0.0, options: [], animations: {
var t = CATransform3DIdentity;
t = CATransform3DMakeRotation(CGFloat(3 * Float.pi / 4), 0, 0, 1)
self.moveableLineLayer.transform = t;
}, completion:{(finished:Bool) in })
}
func openMessageWithoutAnimation() {
self.moveableLineLayer.transform = CATransform3DIdentity
var t = CATransform3DIdentity;
t = CATransform3DMakeRotation(CGFloat(3 * Float.pi / 4), 0, 0, 1)
self.moveableLineLayer.transform = t;
}
最佳答案
考虑使用 velocity
参数。来自文档:
速度
初始 Spring 速度。为了顺利启动动画,请将此值与 View 在连接之前的速度相匹配。 值 1 对应于一秒内遍历的总动画距离。例如,如果总动画距离为 200 点并且您希望动画的开始与 100 pt/s 的 View 速度相匹配,则使用值 0.5。
关于快速动画持续时间,即使我不想(自动?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43595673/