如何使这个动画工作?

时间:2017-10-28 16:10:21

标签: swift animation

我试图使用本教程设置一组图像的动画:https://www.geekylemon.com/animated-loading-screen。我将代码从目标c转换为swift,以便将其实现到另一个项目中,但似乎它无法正常工作。 好吧,在故事板上有三个图像视图(AnitmationimageView与“L1.png”,Loadimageview和视图控制器的背景图像相同)。我想运行AnitmationimageView,之后转换到L1,2,3,4图像,然后转到Loadimageview,然后转到背景图像。但是当我运行程序时,它只显示从AnitmationimageView到Loadimageview的转换以及从Loadimageview到背景图像的转换。希望这有助于“诊断”我的问题。

class ViewController: UIViewController {
    @IBOutlet weak var AnitmationimageView: UIImageView!

    @IBOutlet weak var Loadimageview: UIImageView!
    var loading_1: UIImage!
    var loading_2: UIImage!
    var loading_3: UIImage!

    override func viewDidLoad() {
        super.viewDidLoad()

        AnitmationimageView.animationImages = [UIImage(named: "L1.png"), UIImage(named: "L2.png"), UIImage(named: "L3.png"), UIImage(named: "L4.png")] as? [UIImage]
        AnitmationimageView.animationRepeatCount = 1
        AnitmationimageView.animationDuration = 3 as CFTimeInterval 
        AnitmationimageView.startAnimating()
        perform(#selector(self.delay1), with: nil, afterDelay: 3)
        delay1()
        delay2()
        delay3()
    }

    @objc func delay1() {
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(1.0)
        AnitmationimageView.alpha = 0
        UIView.commitAnimations()
        perform(#selector(self.delay2), with: nil, afterDelay: 1.0)
    }

    @objc func delay2() {
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(1.0)
        Loadimageview.alpha = 1
        UIView.commitAnimations()
        perform(#selector(self.delay3), with: nil, afterDelay: 1.5)
    }

    @objc func delay3() {
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(1.0)
        Loadimageview.alpha = 0
        UIView.commitAnimations()
    }
}

0 个答案:

没有答案