Search code examples
iosswiftsegue

Change ViewController after animation


I have created this animation for the first screen of the app(I'm not using Launchscreen) but when the animation ends I don't know how to pass to the next view controller. I've tired by segue but nothing :/

import UIKit
class ViewController: UIViewController {
    @IBOutlet weak var logoLSMini: UIImageView!
    @IBOutlet weak var logoLSMini2: UIImageView!
    @IBOutlet weak var logoLS: UIImageView!

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.logoLSMini.alpha = 0.0
        self.logoLSMini2.alpha = 0.0
        self.logoLS.alpha = 0.0
        self.logoLS.frame.origin.y = +100


    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        UIView.animate(withDuration: 5, delay: 0.0, options: .curveEaseOut , animations: {
            //FIRST EFFECT

            self.logoLSMini.alpha = 1.0
            self.logoLSMini.transform = CGAffineTransform(rotationAngle: 360)
            self.logoLSMini.transform = CGAffineTransform(scaleX: 100, y: 100)
            self.logoLS.alpha = 1.0

        }, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

Solution

  • You simply need to perform the segue in the completion of UIView.animate. Just make sure you substitute whatever identifier you added to your segue in Storyboard for yourSegue.

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        UIView.animate(withDuration: 5, delay: 0.0, options: .curveEaseOut , animations: {
            //FIRST EFFECT
            self.logoLSMini.alpha = 1.0
            self.logoLSMini.transform = CGAffineTransform(rotationAngle: 360)
            self.logoLSMini.transform = CGAffineTransform(scaleX: 100, y: 100)
            self.logoLS.alpha = 1.0
        }, completion: { _ in
            self.performSegue(withIdentifier: "yourSegue", sender: nil)
        })
    }