swift - Swift - 动画 ImageView
问题描述
只是我在为当前应用程序设置动画移动背景图像视图时遇到的一个快速问题。本质上,我想让我当前静止的背景图像视图无休止地向上滚动到开始位置;但我正在努力将它们拼凑在一起。有人能帮我吗?
class Flash: UIViewController {
@IBOutlet weak var arrowImage: UIImageView!
var arrow1: UIImage!
var arrow2: UIImage!
var arrow3: UIImage!
var images: [UIImage]!
var animatedImage: UIImage!
override func viewDidLoad() {
super.viewDidLoad()
toggleFlash()
arrow1 = UIImage(named: "Arrow1.png")
arrow2 = UIImage(named: "Arrow2.png")
arrow3 = UIImage(named: "Arrow3.png")
images = [arrow1, arrow2, arrow3]
animatedImage = UIImage.animatedImage(with: images, duration: 1.0)
arrowImage.image = animatedImage
}
func blinkScreen(){
UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .curveLinear], animations: {
}) { _ in
}
}
解决方案
好的,我想我明白你要做什么。
首先,duration 参数是动画每次迭代的持续时间。其次, UIView.animate(...) 不会重复动画,除非您将 .repeat 选项添加到 options 参数。
因此,要实现更接近您想要的东西,请将您的代码更新为:
func blinkScreen()
UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .curveLinear], animations: {
self.imageV.transform = CGAffineTransform(translationX: 0, y: -10)
}) { _ in
self.imageV.transform = .identity
}
}
如果您想为上下移动设置动画,请使用 .autoreverse 选项(可能还有 .curveEaseInOut):
func blinkScreen()
UIView.animate(withDuration: 1, delay: 0, options: [.repeat, .autoreverse, .curveEaseInOut], animations: {
self.imageV.transform = CGAffineTransform(translationX: 0, y: -10)
}) { _ in
self.imageV.transform = .identity
}
}
推荐阅读
- firebase - Flutter Firebase:如何刷新 Firebase 用户对象?
- kotlin - 为什么“窗口化”的结果不同?
- java - Java & XML:使用 getNextSibling() 与 getChildNode() 的说明
- docker - docker-compose up airflow-init 挂起:容器之间没有网络连接
- html - 如何在角度模板中使用 localStorage?
- javascript - 如何用 PHP 函数数据替换 javascript 选择框?
- node.js - 如何使用node js从netsuite rest web services获取数据?
- git - 无法将提交推送到主分支:预接收挂钩拒绝错误
- laravel - VueJS Axios链请求动态数组vs静态数组报错
- javascript - 拼接到新的阵列行后,对接收阵列所做的更改会反映在它和源阵列中。为什么?