when my app comes out of the background the animation has stopped. which is normal. but i want to restart my animation from the current state. how do i do that without my snapping all over the place.
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{ [bg setFrame:CGRectMake(0, 0, 1378, 1005)]; } completion:nil];
i tried putting a set frame in front of the animation but that just makes it snap.
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
any ideas?
One thing to check is that for Pokémon Go Settings — General — Background App refresh is on. If it’s not the app will always restart when it’s put in the background. Eureka! Been trying to fix this for so long, thanks! IOS11 right? It more aggressively shuts down apps in the background if there isn’t enough memory. You have an older iPhone?
This is on an iPhone 6 with 16 GB of memory. One thing to check is that for Pokémon Go Settings — General — Background App refresh is on. If it’s not the app will always restart when it’s put in the background. Eureka! Been trying to fix this for so long, thanks! IOS11 right?
Most of the time if only one other app open (that's the tip), phone will not shut down Pokemon Go when in background. Sometimes it does anyway. This happened to me randomly after an update. Simply minimising it and going straight back on would make it restart. In the end reinstalling the app fixed the issue.
You can add an observer in your class for UIApplicationWillEnterForegroundNotification:
- (void)addNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; } - (void)applicationWillEnterForeground { [self animate]; } - (void)animate { [bg setFrame:CGRectMake(0, 0, 0, 0)]; [UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{ [bg setFrame:CGRectMake(0, 0, 1378, 1005)]; } completion:nil]; }
It is important to set the begin state of the animation (and don't forget to remove the notification observer)
well the answer of @dany_23 could work.
But I came across an other method that works just fine if you don't need to resume your animation but restart your animation, without the view or layer snapping when you reactivate the app.
in the
- (void)applicationWillResignActive:(UIApplication *)application
you call a method in your viewcontroller which implements the following code.
[view.layer removeAllAnimations]; // this following CGRect is the point where your view originally started [bg setFrame:CGRectMake(0, 0, 1378, 1005)];
and in the
- (void)applicationDidBecomeActive:(UIApplication *)application
you call a method in your viewcontroller that just starts the animation. something like
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{ [bg setFrame:CGRectMake(0, 0, 1378, 1005)]; } completion:nil];
Hope this helps, Thanks to all who replied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With