Skip to content

animation stop after enter background #481

Closed
@GeekSprite

Description

@GeekSprite

Lottie-ios Issue

Hello! Sorry you are having an Issue! Please help us make Lottie better by filling everything below out with as much information as you can so we can try to reproduce and fix the issue!

Check these before submitting:

  • Updated to the latest (2.1.3) version of Lottie
    The issue doesnt involve and Unsupported Feature
    This issue isnt related to another open issue

This issue is a

  • Non-Crashing (Visual or otherwise) Bug
    Crashing Bug
    Feature Request
    Regression (Something that once worked doesnt work anymore)

What Platform are you on?

  • MacOS (Specify Platform Version)
    iOS (Specify Platform Version)

Expected Behavior

(Screenshots encouraged)

Actual Behavior

(Screenshots encouraged)

Code Example

Animation JSON

Adding the animation JSON helps us debug the issue faster!

Activity

GeekSprite

GeekSprite commented on Nov 10, 2017

@GeekSprite
Author

I set loopAnimation to YES ,it works fine frist,but when I pressed the home button,and then back the app, the animation stopped

DarthMike

DarthMike commented on Nov 21, 2017

@DarthMike

+1

I think it would be nice to have this as a controllable flag, so the view could handle the pause/resume if it was playing when entering background and becoming active.

BTW thanks for a great project!

plguyim

plguyim commented on Nov 23, 2017

@plguyim

+1
I think it is base on Core animation, so .... how to fix it?

mchangxe

mchangxe commented on Nov 23, 2017

@mchangxe

seeing this same problem... Added an animation as subview to an UIView object, loop is on yes but the animation disappears after a few seconds...

GeekSprite

GeekSprite commented on Dec 4, 2017

@GeekSprite
Author

@Eziooooo In Core Animation ,set CAAnimation removeOnCompletion = NO; can solve this problem, but this don't work for lottie...

wucanqi

wucanqi commented on Dec 12, 2017

@wucanqi

+1 the same problem , emmmmmmmm, so .... somebody tell how to fix plz......

ghost

ghost commented on Dec 15, 2017

@ghost

In viewdidappear you can check isAnimationPlaying property. If Its false call [animationView play]

devnull0000

devnull0000 commented on Dec 21, 2017

@devnull0000

+1 the same problem

GeekSprite

GeekSprite commented on Jan 5, 2018

@GeekSprite
Author

@Brsoyan It wont't work, come to foreground, UIViewController will not call viewdidappear,
but you can observe system Notification --UIApplicationWillEnterForegroundNotification ,but it is kind of stupid.

ezequieloliveiralima

ezequieloliveiralima commented on Jan 20, 2018

@ezequieloliveiralima

I have the same problem, and I have downgraded to V 2.0.3:

pod 'lottie-ios', '2.0.3'

Worked for me...

Osama92

Osama92 commented on Feb 12, 2018

@Osama92

Just implemented viewDidLayoutSubview() method, put the animation within the method and it works fine. Thank you!

Agenric

Agenric commented on Mar 9, 2018

@Agenric

I tried to hook play method in the category's load method and added a listener to UIApplicationDidEnterBackgroundNotification and UIApplicationDidBecomeActiveNotification notifications to solve this problem.
But I don’t know if this will have any risk, or do you have any suggestions?

hezhk3

hezhk3 commented on Apr 8, 2018

@hezhk3

Maybe it's stopping for saving energy.

Just observe UIApplicationWillEnterForegroundNotification in your view controller

[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
    if (![animationView isAnimationPlaying]) {
                [animationView play];
            }
}];
adhamali450

adhamali450 commented on Jun 28, 2018

@adhamali450

Hey!
I had the same problem which is the animation disappear when i leave the page where the animation is located and come back to it later
i solved it although i work on Lottie.Forms but the solution is generic it gonna work for each one of you.
there is some event fired when the animation page loads right regardless your platform is right?
you subscribe to this event and do this:
remove the animation view implemented earlier
insert a new animation object within the same place

it's not very friendly to the performance but it woks since there is no official solution from Lottie themselves

ghost

ghost commented on Jul 4, 2018

@ghost

Have you tried to program a simple delay? My animation was stopping after the first play, then I did:

        DispatchQueue.main.asyncAfter(deadline: .now() + 2) { 
            // Your code with delay
            self.animatedView.loopAnimation = true
            self.animatedView.play()
        }

and it started working. Hope it helps!

21 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DarthMike@buba447@dor4emon@BCWoodard@luyinuo

        Issue actions

          animation stop after enter background · Issue #481 · airbnb/lottie-ios