如何使用SDWebImage在iOS中设置渐进式图像?

cod*_*bot 0 objective-c ios sdwebimage

我试图在我的应用程序中逐步加载图像.基本上我尝试的是在图像加载时,我想显示模糊状态下的满载图像.我试过了,

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:[NSURL URLWithString:@"https://profile.microsoft.com/RegsysProfileCenter/Images/personal_info.jpg"]
                      options:0
                     progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                         [self.profileBtn setImage:[UIImage imageWithData:[NSData dataWithBytes:&receivedSize length:sizeof(receivedSize)] scale:15] forState:UIControlStateNormal];
                     }
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                        if (image) {
                            // [self.profileBtn setImage:image forState:UIControlStateNormal];
                        }
                    }];
Run Code Online (Sandbox Code Playgroud)

是否可以使用SDWebImage逐步加载图像.请帮我解决一下这个.

HSG*_*HSG 6

您可以尝试此实现

+ (void)loadImageWithURLString:(NSString *)urlString forImageView:(UIImageView *)imageView {
    [imageView sd_setImageWithURL:[Utilities stringToURL:urlString]
                 placeholderImage:[UIImage placeHolderImage]
                          options:SDWebImageProgressiveDownload];
}
Run Code Online (Sandbox Code Playgroud)

选项说明了

/**
     * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
     * By default, the image is only displayed once completely downloaded.
     */
    SDWebImageProgressiveDownload = 1 << 3,
Run Code Online (Sandbox Code Playgroud)

  • 如果您想从模糊状态显示图像,我认为一种可能的解决方案是在占位符图像之上创建一个模糊层,模糊值由下载完成的百分比设置。 (2认同)