Sonu Jha
Sonu Jha

Reputation: 719

Unpredictable crash due to UIView animations

I have made a custom activity indicator to use in a project. I rotate a static loader image for that.

- (void) rotate {
    lastInstance++;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(rotate)];
    [UIView setAnimationDuration:0.1];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    spinnerImageView.layer.transform = CATransform3DMakeRotation(M_PI*(lastInstance%10)/5, 0.0, 0.0, 1.0);
    [UIView commitAnimations];
}

The spinnerimageview is contained within a superview container, and it bears the static loader image. It works fine, except for crashing unpredictably without any error messages.

Upvotes: 0

Views: 850

Answers (1)

Jasarien
Jasarien

Reputation: 58448

Looks like you're stuck in a never ending recursion. How do you decide when to stop the rotation?

Each time the rotation animation completes it simply calls rotate again, with seemingly no end in sight.

The crash you are seeing is likely a stack overflow (how apt).

I'd suggest rethinking how to you decide whether the animation could continue.

Upvotes: 1

Related Questions