0

I have an "AViewController" is root viewController and I have an image is playing animation infinite loop.

- (void)rotateImageView
{ 
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        [self.imageViewSpin setTransform:CGAffineTransformRotate(self.imageViewSpin.transform, M_PI_2)];
    }completion:^(BOOL finished){
        if (finished) {
            [self rotateImageView];
        }
    }];
}

in viewWillAppear

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotateImageView) name:UIApplicationWillEnterForegroundNotification object:nil];
    [self rotateImageView];
}

This work great if my application become to active. But when I'm try to presentViewController "CViewController" [self.navigationController presentViewController: animated: completion:] And I have Back button on "CViewController"

[self dismissViewControllerAnimated:YES completion:^{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"checkIsPresent" object:self];
    }];

After returning to "AviewController",animation stops working. How to solve this issue. Thank you.

Edit.

Work now I just put [self rotateImage]; in method from postNotification.

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotateImageView) name:UIApplicationWillEnterForegroundNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkPresentView) name:@"checkIsPresent" object:nil];
    [self rotateImageView];
}
-(void)checkPresentView{
    //isModalView = false;
    [self rotateImageView];
}
user3449256
  • 1
  • 1
  • 1
  • You do not need to add an observer and post notification from CViewController. The [self rotateImageView] method itself will be called as AViewController's `viewWillAppear` will get called when dismissing CViewController – ZeMoon Apr 24 '14 at 05:30
  • Oh, That post notification I'm use for another thing, sorry for that I'll edit it.So from viewWillAppear it's work but my animation not loop just run only 1/4 of a circle and animation will stop. – user3449256 Apr 24 '14 at 06:52
  • You could try calling [view.layer removeAllAnimations]; in viewWillDisappear – ZeMoon Apr 24 '14 at 07:05
  • Thank for suggestion I'll merge it with my working code. – user3449256 Apr 24 '14 at 07:24
  • Great that you have made it work, post your edit as the answer – ZeMoon Apr 24 '14 at 07:30

0 Answers0