gpt4 book ai didi

ios - Swift - 动画 UIImageView 图像

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:32 24 4
gpt4 key购买 nike

我遇到了一个关于为我当前的应用程序设置动画移动背景图像的快速问题。本质上,我想让我当前静止的背景图像在我的 View 中从左到右无休止地滚动;但我正在努力将它们拼凑在一起。从各种其他来源,我已经包含了这个目前无法正常工作的功能,我真的无法弄清楚如何或为什么。

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")
}

希望对您有所帮助。

关于ios - Swift - 动画 UIImageView 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com