Question

I am new in ios developement.I'm implementing Taperecorder project, in which i have some CABasicAnimations used to rotating wheel while recording audio and playing.Everything working fine(recording and playing)... but while recording an audio if i pressed home button again open the app backround recording process working fine wheel animation is not rotating..

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat: 2*M_PI];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.duration = 4.0f;
animation.repeatCount = INFINITY;
[imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
[imageRight.layer addAnimation:animation forKey:@"SpinAnimation"];
Was it helpful?

Solution

Try this...

- (void)viewWillAppear:(BOOL)animated
 {
   [super viewWillAppear:animated];

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addAnimation:) name:UIApplicationWillEnterForegroundNotification object:nil];

}

//How to remove an observer for NSNotification

  [[NSNotificationCenter defaultCenter] removeObserver:self];

OTHER TIPS

Try this..

 - (void)viewWillAppear:(BOOL)animated
 {
      [super viewWillAppear:animated];

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(your   animation method:) name:UIApplicationWillEnterForegroundNotification object:nil];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top