在swift3中结合翻译,alpha和缩放动画

Gil*_*OOl 3 iphone animation cgaffinetransform ios swift3

我完全是iOS Swift开发的新手,我尝试在一个动画中组合三个参数,但我没有成功.

我认为解决方案就在这里 - Apple Dev Core动画编程指南通过对动画进行分组,但作为初学者,经过大量的互联网研究,我找不到我想要的东西.

您如何看待我的代码以及什么是适合您的性能和稳定性的最佳解决方案.

我想指出这个动画的目的是创建一个动画的Splashscreen.还有其他元素(UIImage)将用于动画.

这是我的代码:

    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)
}
Run Code Online (Sandbox Code Playgroud)

agi*_*007 11

基于我所看到的你想要预设动画并将其翻译回来.在那种情况下,我会这样做.

    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)
Run Code Online (Sandbox Code Playgroud)

我想你可能没有看到所有动画,所以尝试以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)
Run Code Online (Sandbox Code Playgroud)

这里的关键是动画动画回原始身份.希望这可以帮助