How to use isAnimating in an iPhone app

2019-08-25 05:29发布

问题:

I want to have a custom loading menu made from a series of stills, that loops 3 times and then reveals a picture. Currently the picture is visible from the start. I want to use isAnimating to find out when the loading animation has stopped, and either change myImage.hidden off, or have the UIImageView initially containing a white image, then being replaced with the picture when isAnimating returns NO.

Apple's website just says

- (BOOL)isAnimating

and that it returns a Boolean YES or NO.

but how do you use this?

I need things to happen depending on whether something is animating or not, so i do i put the result it returns in a variable and check that in the conditional of an if statement?

put it in an if statement itself? or is it a while statement?

or is it like:

- (BOOL)isAnimating{
     //stuff to do if it is
}

or am i just getting the whole concept entirely wrong?

回答1:

I guess isAnimating method just tells you if an UIViewImage is actually performing an animation.
Since you just want to create a short loading before displaying your image, why don't you simply use a timer? You can do something like this

- (void)startAnimation {
    yourImageView.hidden = YES; // Keep you image hidden while loading
    [yourLoadingAnimation startAnimating]; // Start you loading animation
    NSInteger timeout = 2; // Duration in seconds of your loading animation
    [NSTimer scheduledTimerWithTimeInterval:timeout target:self selector:@selector(stopAnimation) userInfo:nil repeats:NO]; // Set the timer
}

- (void)stopAnimation {
    [yourLoadingAnimation stopAnimating]; // Stop your loading animation
    yourLoadingAnimation.hidden = YES; // Hide your laading animation
    yourImageView.hidden = NO; // Display your image
}