[英]Swift - animating UIImageView image
我正在为我当前的应用程序设置动画移动背景图像做一个快速的问题。 基本上我想让我当前的静态背景图像在我的视图中无休止地从左到右滚动; 但我正在努力拼凑它们。 从各种其他来源我已经包含这个目前无法正常工作的功能,我真的无法弄清楚如何或为什么。
func animate(_ image: UIImageView) {
UIView.animate(withDuration: 5, delay: 0, options: .curveLinear, animations: {
image.transform = CGAffineTransform(translationX: -100, y: 0)
}) { (success: Bool) in
image.transform = CGAffineTransform.identity
self.animate(image)
}
}
非常感谢任何帮助/帮助!
您不需要在animateWithDuration
使用CAffineTranform
,您可以简单地定义新的中心,如:
let oldCenter = image.center
let newCenter = CGPoint(x: oldCenter.x - 100, y: oldCenter.y)
UIView.animate(withDuration: 1, delay: 0, options: .curveLinear, animations: {
image.center = newCenter
}) { (success: Bool) in
print("Done moving image")
}
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.