简体   繁体   中英

Animations don't work when scrolling UIScrollView

I have a UIScrollView that has a bunch of items in it, similar to a facebook feed. In that feed I have a bunch of images that are being loaded from the internet. When the images are loaded they fade in. The problem is that if I am scrolling the scroll view, then the image animation to fade in doesn't occur until my finger is lifted off the scrollview. Is there any way to update the subviews of the UIScrollView view while scrolling?

-(void)loadStuff:(DipticView*)diptic{
    //DipticView is a UIView subclass that holds the imageview and some other information
    ConnectionManager *conman = [[ConnectionManager alloc] init];
    WebImage *webimage = [diptic.item.images firstObject]; //webimage holds the imageurl and the image

    [conman getImageWithURL:webimage.image_URL inBackgroundWithBlock:^(NSString *error, id image) {
        webimage.image = image;
        diptic.imageView.image = image;
        diptic.imageView.alpha = 0;
        diptic.userInteractionEnabled = NO;
        [UIView animateWithDuration:.4 animations:^{
            diptic.imageView.alpha = 1;
        } completion:^(BOOL finished) {
            diptic.userInteractionEnabled = YES;
        }];
        //The diptics are all subviews of the scrollview.
    }];
}
   dispatch_async(dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:.4 animations:^{
        diptic.imageView.alpha = 1;
    } completion:^(BOOL finished) {
        diptic.userInteractionEnabled = YES;
    }];
});

But I'm not sure that this method can work well with animateWithDuration.

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