How can I run my gif only once using FLAnimatedImage?











up vote
0
down vote

favorite












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
    14 hours ago

















up vote
0
down vote

favorite












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
    14 hours ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 12 hours ago









Dávid Pásztor

19.2k72547




19.2k72547










asked 14 hours ago









z_rou

73




73












  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…
    – Vlad
    14 hours ago




















  • you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…
    – Vlad
    14 hours ago


















you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…
– Vlad
14 hours ago






you can play with properties: loopLeft and loopCountdown: dndgit.com/marek/FLAnimatedImage/commit/…
– Vlad
14 hours ago














2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










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?
    – z_rou
    10 hours ago










  • Yes, where you configure the imageView, typically in the ViewController.
    – Akos Komuves
    9 hours ago










  • Thanks a lot, It works.
    – z_rou
    5 hours ago


















up vote
0
down vote













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',
    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








    up vote
    1
    down vote



    accepted










    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?
      – z_rou
      10 hours ago










    • Yes, where you configure the imageView, typically in the ViewController.
      – Akos Komuves
      9 hours ago










    • Thanks a lot, It works.
      – z_rou
      5 hours ago















    up vote
    1
    down vote



    accepted










    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?
      – z_rou
      10 hours ago










    • Yes, where you configure the imageView, typically in the ViewController.
      – Akos Komuves
      9 hours ago










    • Thanks a lot, It works.
      – z_rou
      5 hours ago













    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    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 14 hours ago









    Akos Komuves

    265




    265












    • Thanks, for your response. Should I write it in my ViewController.swift file?
      – z_rou
      10 hours ago










    • Yes, where you configure the imageView, typically in the ViewController.
      – Akos Komuves
      9 hours ago










    • Thanks a lot, It works.
      – z_rou
      5 hours ago


















    • Thanks, for your response. Should I write it in my ViewController.swift file?
      – z_rou
      10 hours ago










    • Yes, where you configure the imageView, typically in the ViewController.
      – Akos Komuves
      9 hours ago










    • Thanks a lot, It works.
      – z_rou
      5 hours ago
















    Thanks, for your response. Should I write it in my ViewController.swift file?
    – z_rou
    10 hours ago




    Thanks, for your response. Should I write it in my ViewController.swift file?
    – z_rou
    10 hours ago












    Yes, where you configure the imageView, typically in the ViewController.
    – Akos Komuves
    9 hours ago




    Yes, where you configure the imageView, typically in the ViewController.
    – Akos Komuves
    9 hours ago












    Thanks a lot, It works.
    – z_rou
    5 hours ago




    Thanks a lot, It works.
    – z_rou
    5 hours ago












    up vote
    0
    down vote













    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



























      up vote
      0
      down vote













      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

























        up vote
        0
        down vote










        up vote
        0
        down vote









        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 14 hours ago

























        answered 14 hours ago









        Abu Ul Hassan

        233218




        233218






























             

            draft saved


            draft discarded



















































             


            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







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules