I have a number of animations that start automatically when my root view controller is loaded. These animations are included in viewDidLoad
. When i navigate to my next view controller and return to the root view controller, all the animations have stopped. The same behaviour occurs when i press the "home" button and then return to the the view.
I'm sure i'm missing something very basic here but would appreciate any help. Thanks.
EDIT 1:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self beeBobbing];
//animate the butterfly oscillating
[self butterflyOscillate];
}
-(void) beeBobbing
{
[UIView animateWithDuration:1.0f delay:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction ) animations:^{
CGPoint bottomPoint = CGPointMake(215.0, 380.0);
imgBee.center = bottomPoint;
} completion:^(BOOL finished) {
}];
}
EDIT 2: This type of animation seems to restart when changing between views:
-(void) animateClouds
{
[UIView animateWithDuration:30.0f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
CGPoint leftScreenCenter = CGPointMake(-420.0, 119.0);
imgClouds.center = leftScreenCenter;
} completion:^(BOOL finished) {
CGPoint rightScreenCenter = CGPointMake(1450.0, 119.0);
imgClouds.center = rightScreenCenter;
[UIView animateWithDuration:40.0f delay:0 options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat) animations:^{
CGPoint leftScreenCenter = CGPointMake(-420.0, 119.0);
imgClouds.center = leftScreenCenter;
} completion:^(BOOL finished) {
}];
}];
}
You need to add the animations in viewWillAppear:
. viewDidLoad
is called once when the controller is initialized and the view is loaded either from a nib or created in the -loadView
method (if overridden) and won't be called again until the controller is destroyed and created again. The methods that fire when you navigate back and forward are viewWillAppear:
viewDidAppear
viewWillDisappear:
.
i think if you give all animation in viewWillAppear:
then its work fine...
thats it...
:)
viewDidLoad is just called when you first load your controller the first time, if then you navigate to other viewControllers with some push or you change tab, you don't pass in viewDidLoad...
try to start your animations in the method - (void)viewWillAppear:(BOOL)animated
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