关于我当前应用程序设置的动态背景图像动画,我遇到的一个快速问题。本质上,我想让当前静止的背景图像视图不断向上滚动以开始位置;但我正在努力将它们拼凑在一起。有人可以帮我吗?
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
}
}
答案 0 :(得分:0)
好吧,我想我知道你要做什么。
首先,duration参数是动画每次迭代的持续时间。其次,除非将.repeat选项添加到options参数,否则UIView.animate(...)不会重复动画。
因此,要实现更接近所需的目标,请将代码更新为:
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
}
}