简体   繁体   中英

SwiftyGif loop freezes when code continues to execute

I'm using SwiftyGif to display an animated gif inside of a view controller. Since you cant use an animated gif in a launch screen, my initial view controller is just an animated gif. What I'd like to do is have the gif loop while the app runs some initial queries, then move to the next view controller when all of the data is staged. When I run it with just the code to display the gif, it works as expected. As soon as other code is introduced after the gif code block, the gif stops working. It looks like the SwiftyGif code only loops if nothing else follows. Has anyone else run into this issue? I've tried everything I can think of including running gif block async and nothing is working. If there is a better gif library that's fine too.


override func viewDidAppear(_ animated: Bool) {
    
    //THIS WORKS FINE
    do{
        //START LOOPING THE ANIMATED LOGO
        let animatedLogoGIF = try UIImage(gifName: "animatedlogo.gif")
        self.AnimatedLogo.setGifImage(animatedLogoGIF, loopCount: 10)
        self.AnimatedLogo.startAnimatingGif()

        
    } catch {
        print(error)
    }
    
    
    //WHEN THIS IS ADDED THE GIF NEVER START LOOPING OR STOPS IMMEDIATELY
    var i: Float = 0
    while (i < 10000000)
    {
        i += 0.01
    }

The GIF wants to animate on the main thread, so do your data loading asynchronously on a background thread. Then, when it's done, you can change the view (make sure to do this on the main thread)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM