【发布时间】:2016-09-28 10:22:49
【问题描述】:
我刚从 obj C 迁移到 swift,我不确定为什么它不起作用,因为在 obj c 中它工作正常,请查看我的代码
这是我的代码
func addAnimationOnLayer( layer: CALayer, position: CGPoint, duration: TimeInterval, delay: TimeInterval, fromPosition: CGPoint, toPostion: CGPoint, key: String) {
layer.setAffineTransform(CGAffineTransform(translationX: position.x, y: position.y))
CATransaction.begin()
CATransaction.setCompletionBlock {
layer.setAffineTransform(CGAffineTransform(translationX: 0, y: 0))
}
let theAnimation = CABasicAnimation(keyPath: "transform.translation")
theAnimation.isRemovedOnCompletion = false
theAnimation.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut)
theAnimation.fillMode = kCAFillModeForwards
theAnimation.duration = duration
theAnimation.beginTime = delay
theAnimation.fromValue = fromPosition
theAnimation.toValue = toPostion
layer.add(theAnimation, forKey: key)
CATransaction.commit()
}
我用这个调用函数
self.addAnimationOnLayer(layer: self.logoImage.layer, position: CGPoint(x: 0, y:100), duration: 0.8, delay: 0.1, fromPosition: CGPoint(x: 0,y: 100), toPostion: CGPoint(x: 0,y: 0), key: "logoStartAnimation")
【问题讨论】: