How can I run my gif only once using FLAnimatedImage?












0















I'm using xcode 10.1 and swift 4.2, I have a gif which I made with Photoshop and it plays one time in browser and in android studio.
But when I import it in xcode and click on it in storyboard, it plays for ever. It also plays several time in my virtual simulator.



I'm creating an IOS webview app and I want to play this gif once in my splash screen and stop it at the last frame, until my webview loads.



I'm using FLAnimatedImage, I found a similar question to mine, but I couldn't find my solution. That's why I'm asking again.



I do not want to change the main library files, since I have another gif which I want to play it forever. So I just need to stop the first gif in the last frame.



You can see a small part of my code:



@IBOutlet var LogoView: FLAnimatedImageView!

LogoView.contentMode = UIView.ContentMode.scaleAspectFit
LogoView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
LogoView!.autoresizingMask = [.flexibleWidth, .flexibleHeight]

let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo_gif", withExtension: "gif")!)
LogoView.animatedImage = FLAnimatedImage(animatedGIFData: imageData)


Thanks in advance :)










share|improve this question

























  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

    – Vlad
    Nov 19 '18 at 10:14


















0















I'm using xcode 10.1 and swift 4.2, I have a gif which I made with Photoshop and it plays one time in browser and in android studio.
But when I import it in xcode and click on it in storyboard, it plays for ever. It also plays several time in my virtual simulator.



I'm creating an IOS webview app and I want to play this gif once in my splash screen and stop it at the last frame, until my webview loads.



I'm using FLAnimatedImage, I found a similar question to mine, but I couldn't find my solution. That's why I'm asking again.



I do not want to change the main library files, since I have another gif which I want to play it forever. So I just need to stop the first gif in the last frame.



You can see a small part of my code:



@IBOutlet var LogoView: FLAnimatedImageView!

LogoView.contentMode = UIView.ContentMode.scaleAspectFit
LogoView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
LogoView!.autoresizingMask = [.flexibleWidth, .flexibleHeight]

let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo_gif", withExtension: "gif")!)
LogoView.animatedImage = FLAnimatedImage(animatedGIFData: imageData)


Thanks in advance :)










share|improve this question

























  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

    – Vlad
    Nov 19 '18 at 10:14
















0












0








0








I'm using xcode 10.1 and swift 4.2, I have a gif which I made with Photoshop and it plays one time in browser and in android studio.
But when I import it in xcode and click on it in storyboard, it plays for ever. It also plays several time in my virtual simulator.



I'm creating an IOS webview app and I want to play this gif once in my splash screen and stop it at the last frame, until my webview loads.



I'm using FLAnimatedImage, I found a similar question to mine, but I couldn't find my solution. That's why I'm asking again.



I do not want to change the main library files, since I have another gif which I want to play it forever. So I just need to stop the first gif in the last frame.



You can see a small part of my code:



@IBOutlet var LogoView: FLAnimatedImageView!

LogoView.contentMode = UIView.ContentMode.scaleAspectFit
LogoView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
LogoView!.autoresizingMask = [.flexibleWidth, .flexibleHeight]

let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo_gif", withExtension: "gif")!)
LogoView.animatedImage = FLAnimatedImage(animatedGIFData: imageData)


Thanks in advance :)










share|improve this question
















I'm using xcode 10.1 and swift 4.2, I have a gif which I made with Photoshop and it plays one time in browser and in android studio.
But when I import it in xcode and click on it in storyboard, it plays for ever. It also plays several time in my virtual simulator.



I'm creating an IOS webview app and I want to play this gif once in my splash screen and stop it at the last frame, until my webview loads.



I'm using FLAnimatedImage, I found a similar question to mine, but I couldn't find my solution. That's why I'm asking again.



I do not want to change the main library files, since I have another gif which I want to play it forever. So I just need to stop the first gif in the last frame.



You can see a small part of my code:



@IBOutlet var LogoView: FLAnimatedImageView!

LogoView.contentMode = UIView.ContentMode.scaleAspectFit
LogoView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
LogoView!.autoresizingMask = [.flexibleWidth, .flexibleHeight]

let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo_gif", withExtension: "gif")!)
LogoView.animatedImage = FLAnimatedImage(animatedGIFData: imageData)


Thanks in advance :)







ios swift gif






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 11:24









Dávid Pásztor

21.9k82749




21.9k82749










asked Nov 19 '18 at 9:44









user_5user_5

74




74













  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

    – Vlad
    Nov 19 '18 at 10:14





















  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

    – Vlad
    Nov 19 '18 at 10:14



















you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

– Vlad
Nov 19 '18 at 10:14







you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…

– Vlad
Nov 19 '18 at 10:14














2 Answers
2






active

oldest

votes


















1














You can give a loopCompletionBlock to your imageView



self.imageView.loopCompletionBlock = {_ in
self.imageView.stopAnimating()
}





share|improve this answer
























  • Thanks, for your response. Should I write it in my ViewController.swift file?

    – user_5
    Nov 19 '18 at 14:11











  • Yes, where you configure the imageView, typically in the ViewController.

    – Akos Komuves
    Nov 19 '18 at 14:34











  • Thanks a lot, It works.

    – user_5
    Nov 19 '18 at 18:24



















0














You may use following library.



https://github.com/wangjwchn/AImage



   let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

/* Create AImageView */
let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

/* Add AImage to AImageView */
imageview.add(image: image!)

/* Start displaying animated image */
imageview.play = true

...
...

/* Stop displaying animated image */
imageview.play = false


pass true to play property when you want it to start and and pass false when you want to stop.



You can also use this AImageView class from storyboard too, change UIImageView to AImageView from class inspector.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371912%2fhow-can-i-run-my-gif-only-once-using-flanimatedimage%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can give a loopCompletionBlock to your imageView



    self.imageView.loopCompletionBlock = {_ in
    self.imageView.stopAnimating()
    }





    share|improve this answer
























    • Thanks, for your response. Should I write it in my ViewController.swift file?

      – user_5
      Nov 19 '18 at 14:11











    • Yes, where you configure the imageView, typically in the ViewController.

      – Akos Komuves
      Nov 19 '18 at 14:34











    • Thanks a lot, It works.

      – user_5
      Nov 19 '18 at 18:24
















    1














    You can give a loopCompletionBlock to your imageView



    self.imageView.loopCompletionBlock = {_ in
    self.imageView.stopAnimating()
    }





    share|improve this answer
























    • Thanks, for your response. Should I write it in my ViewController.swift file?

      – user_5
      Nov 19 '18 at 14:11











    • Yes, where you configure the imageView, typically in the ViewController.

      – Akos Komuves
      Nov 19 '18 at 14:34











    • Thanks a lot, It works.

      – user_5
      Nov 19 '18 at 18:24














    1












    1








    1







    You can give a loopCompletionBlock to your imageView



    self.imageView.loopCompletionBlock = {_ in
    self.imageView.stopAnimating()
    }





    share|improve this answer













    You can give a loopCompletionBlock to your imageView



    self.imageView.loopCompletionBlock = {_ in
    self.imageView.stopAnimating()
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 '18 at 10:12









    Akos KomuvesAkos Komuves

    418




    418













    • Thanks, for your response. Should I write it in my ViewController.swift file?

      – user_5
      Nov 19 '18 at 14:11











    • Yes, where you configure the imageView, typically in the ViewController.

      – Akos Komuves
      Nov 19 '18 at 14:34











    • Thanks a lot, It works.

      – user_5
      Nov 19 '18 at 18:24



















    • Thanks, for your response. Should I write it in my ViewController.swift file?

      – user_5
      Nov 19 '18 at 14:11











    • Yes, where you configure the imageView, typically in the ViewController.

      – Akos Komuves
      Nov 19 '18 at 14:34











    • Thanks a lot, It works.

      – user_5
      Nov 19 '18 at 18:24

















    Thanks, for your response. Should I write it in my ViewController.swift file?

    – user_5
    Nov 19 '18 at 14:11





    Thanks, for your response. Should I write it in my ViewController.swift file?

    – user_5
    Nov 19 '18 at 14:11













    Yes, where you configure the imageView, typically in the ViewController.

    – Akos Komuves
    Nov 19 '18 at 14:34





    Yes, where you configure the imageView, typically in the ViewController.

    – Akos Komuves
    Nov 19 '18 at 14:34













    Thanks a lot, It works.

    – user_5
    Nov 19 '18 at 18:24





    Thanks a lot, It works.

    – user_5
    Nov 19 '18 at 18:24













    0














    You may use following library.



    https://github.com/wangjwchn/AImage



       let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

    /* Create AImageView */
    let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

    /* Add AImage to AImageView */
    imageview.add(image: image!)

    /* Start displaying animated image */
    imageview.play = true

    ...
    ...

    /* Stop displaying animated image */
    imageview.play = false


    pass true to play property when you want it to start and and pass false when you want to stop.



    You can also use this AImageView class from storyboard too, change UIImageView to AImageView from class inspector.






    share|improve this answer






























      0














      You may use following library.



      https://github.com/wangjwchn/AImage



         let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

      /* Create AImageView */
      let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

      /* Add AImage to AImageView */
      imageview.add(image: image!)

      /* Start displaying animated image */
      imageview.play = true

      ...
      ...

      /* Stop displaying animated image */
      imageview.play = false


      pass true to play property when you want it to start and and pass false when you want to stop.



      You can also use this AImageView class from storyboard too, change UIImageView to AImageView from class inspector.






      share|improve this answer




























        0












        0








        0







        You may use following library.



        https://github.com/wangjwchn/AImage



           let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

        /* Create AImageView */
        let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

        /* Add AImage to AImageView */
        imageview.add(image: image!)

        /* Start displaying animated image */
        imageview.play = true

        ...
        ...

        /* Stop displaying animated image */
        imageview.play = false


        pass true to play property when you want it to start and and pass false when you want to stop.



        You can also use this AImageView class from storyboard too, change UIImageView to AImageView from class inspector.






        share|improve this answer















        You may use following library.



        https://github.com/wangjwchn/AImage



           let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

        /* Create AImageView */
        let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

        /* Add AImage to AImageView */
        imageview.add(image: image!)

        /* Start displaying animated image */
        imageview.play = true

        ...
        ...

        /* Stop displaying animated image */
        imageview.play = false


        pass true to play property when you want it to start and and pass false when you want to stop.



        You can also use this AImageView class from storyboard too, change UIImageView to AImageView from class inspector.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '18 at 10:15

























        answered Nov 19 '18 at 10:07









        Abu Ul HassanAbu Ul Hassan

        252218




        252218






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371912%2fhow-can-i-run-my-gif-only-once-using-flanimatedimage%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings