iOS UIView Animation Issue

2020-04-21 06:36发布

问题:

I have an issue with a UIView animation when switching between pages in a UITabBarController.

A view in UIViewControllerA is playing the following animation:-

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
        self.animationImageView.transform = transform;
    } completion:NULL];

The animation is a custom loading wheel which stops when a song has been loaded.

If I switch between pages, i.e. from UIViewControllerA to UIViewControllerB and then back to A in a UITabController the animation stops. It does not animate again when I try to restart it.

回答1:

The answer is simple, reset the transform:

self.animationImageView.transform = CGAffineTransformIdentity;