user648753
user648753

Reputation: 167

Animation won't restart after view change

First time the view loads the animation is applied but after that when ever the view is loaded - nothing happens.

Should be straightforward - but...

The code:

- (void)viewDidAppear:(BOOL)animated{    
[self animateLabel];    
}

- (void)viewWillDisappear:(BOOL)animated{
[self.labelMarkTheSpot.layer removeAllAnimations];  
}

- (void)animateLabel{

UIViewAnimationOptions options = (UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState);

CGAffineTransform scaleFactor = CGAffineTransformMakeScale(1.1, 1.1);
[UIView animateWithDuration:0.2 delay:0 options:options animations:^{
    self.labelMarkTheSpot.transform = scaleFactor;        
}
completion:nil];
}

(starting the animation in viewWillAppear makes no difference)

Upvotes: 2

Views: 241

Answers (1)

Alexander Obenauer
Alexander Obenauer

Reputation: 127

Add a line at the beginning of animateLabel to reset the view to its scale before the animation:

self.labelMarkTheSpot.transform = CGAffineTransformMakeScale(1.0, 1.0);

What's happening is once it has animated to 1.1, 1.1; it stays that way, and the animation when the view re-appears doesn't do anything (1.1 to 1.1). By resetting it to 1.0 (or whatever you want it to initially be, as the starting point for the animation), it will always go from 1.0 to 1.1.

Upvotes: 3

Related Questions