在swift3中结合翻译,alpha和缩放动画 [英] Combine translation, alpha and scale animations in swift3
问题描述
我完全是iOS Swift开发的新手,我尝试在单个动画中结合三个参数,但我没有成功。
I'm totally newbies with iOS Swift developement and i try to combine three parameters in a single animations but i don't succeed.
我认为解决方案是此处- Apple Dev Core动画编程指南,通过将动画分组但还是一个初学者,经过大量的互联网研究,我找不到我想要的东西。
I think the solution is here -Apple Dev Core Animation Programming Guide by grouping the animations but being a beginner and after a lot of Internet research i can't find what i'm looking for.
您如何看待我的代码,以及什么是为您提供结合性能和稳定性的最佳解决方案。
What do you think of my code and what is for you the best solution to combine performance and stability.
我想指出的是,此动画的目的是创建动画的启动画面。还有其他元素(UIImage)可以进行动画处理。
I want to point out that the purpose of this animation is to create an animated Splashscreen. There are other elements (UIImage) that will be to animates.
这是我的代码:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
logoImg.alpha = 0
logoImg.transform = CGAffineTransform(translationX: 0, y: -200)
logoImg.transform = CGAffineTransform(scaleX: 0, y: 0)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 1.0, delay: 1.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [.curveEaseOut], animations: {
self.logoImg.transform = CGAffineTransform(translationX: 0, y: 0)
self.logoImg.transform = CGAffineTransform(scaleX: 1, y: 1)
self.logoImg.alpha = 1
}, completion: nil)
}
推荐答案
根据我所看到的,您想提出的建议t动画并将其翻译回去。在那种情况下,我会这样做。
Based on what I am seeing you are wanting to preset the animation and translate it back. In that case I would do this.
self.logoImg.transform = CGAffineTransform(translationX: 0, y: -200).concatenating(CGAffineTransform(scaleX: 0, y: 0))
self.logoImg.alpha = 0
UIView.animate(withDuration: 1.0, delay: 1.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [.curveEaseOut], animations: {
self.logoImg.transform = .identity
self.logoImg.alpha = 1
}, completion: nil)
我认为您可能看不到所有动画,因此尝试将缩放比例从0.5开始
I think you may not be seeing all the animation so try to start the scale at 0.5
self.logoImg.transform = CGAffineTransform(translationX: 0, y: -200).concatenating(CGAffineTransform(scaleX: 0.5, y: 0.5))
self.logoImg.alpha = 0
UIView.animate(withDuration: 1.0, delay: 1.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 1, options: [.curveEaseOut], animations: {
self.logoImg.transform = .identity
self.logoImg.alpha = 1
}, completion: nil)
这里的关键是动画正在动画化原始身份。希望这会有所帮助
The key here is that the animation is animating back the original identity. Hope this helps
这篇关于在swift3中结合翻译,alpha和缩放动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!