0

I have a CABasicAnimation in the viewWillAppear method of "viewA". when I press a button in viewA to go to viewB and then go back to viewA the CABasicAnimation in the viewWillAppear (of viewA) works without problem.

but, when I go from viewA to viewB, and in viewB I resign the application by pressing the home button and return back to the app, the CABasicAnimation in viewWillAppear of viewA doesn't trigger after I've pressed the back button in viewB.

The funny thing is that I also have an animation block in the viewWillAppear and that triggers without any problem in this scenario. so the viewWillAppear method is triggered it's just the CABasicAnimation that doesn't work the first time after resigning and entering the app.

- (void) viewWillAppear:(BOOL)animated {

CAMediaTimingFunction *customTimingFunction;
    customTimingFunction=[CAMediaTimingFunction functionWithControlPoints: 0.5f :0.01f :0.1f : 1.f];

    CABasicAnimation *buttonAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation"];

    buttonAnimation.fromValue=[NSValue valueWithCGPoint:CGPointMake(0,-600)];
    buttonAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake(0,0)];
    buttonAnimation.duration = 1;
    buttonAnimation.removedOnCompletion = NO;
    buttonAnimation.fillMode = kCAFillModeForwards;
    buttonAnimation.timingFunction = customTimingFunction;
    [button.layer addAnimation:buttonAnimation forKey:@"transform.translation"];

}
Ramin Afshar
  • 989
  • 2
  • 18
  • 34
  • One solution I've found is to place the code in viewDidAppear. however, I think the animation triggers slightly too late because it's in the viewDidAppear method. Ideally I'd want it in the viewWillAppear. – Ramin Afshar May 05 '12 at 20:38

2 Answers2

3

I've found the solution. if I change buttonAnimation.removedOnCompletion = NO; to change buttonAnimation.removedOnCompletion = YES; it will trigger every time. even after resign and entering the app.

Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
Ramin Afshar
  • 989
  • 2
  • 18
  • 34
0

I`m getting the same case, animation does not start. Using code from here: https://github.com/akaabe/HamburgerButton/blob/master/HamburBtn.m and calling in viewDidAppear toggleAnimation. Only case that is working for me is to use performSelector with delay.

Dimitrio
  • 151
  • 4
  • 12