简体   繁体   中英

Stop animating UIActivityIndicatorView when UIImageView image has finished loading

I want to display the spinning activity view over a UIImageView and stop and hide the activity view once the image has finished loading and is displayed. The image is a large photograph taken from the assets-library.

- (void)viewDidLoad
{
    //set photo
    UIImageView *Photo = _photo;
    NSURL *url = [[NSURL alloc] initWithString:project.photo];
    ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

    [library assetForURL:url resultBlock:^(ALAsset *asset) {

        ALAssetRepresentation *rep = [asset defaultRepresentation];
        CGImageRef iref = [rep fullResolutionImage];
        if (iref) {
            self.photo.image = [UIImage imageWithCGImage:[rep fullScreenImage] scale:[rep scale] orientation:0];

        }
             } failureBlock:^(NSError *error) {

                 NSLog(@"Couldn't load asset %@ => %@", error, [error localizedDescription]);



             }];

    [_ImageLoader stopAnimating];
}

This, however, does not work as the activity view is constantly spinning.

The spinner is always animated because

- (void)viewWillAppear:(BOOL)animated;

is called after

- (void)viewDidLoad

So basically your telling the spinner to animate after telling it to stop.

Good luck!

Helium is right. You want to move the cal to [_ImageLoader stopAnimating] inside the result block, or you end up stopping the animation before it even started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM