码迷,mamicode.com
首页 > Web开发 > 详细

SDWebImage下载图片有时候无法成功显示出来

时间:2015-11-05 10:21:42      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

之前用下面的方法现在图片,有时候会出现图片没有下载成功显示:

 - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;

 后来研究下,还有下面的方法:

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;

 重点就在这个SDWebImageOptions上,文档提示如下:

typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {

    /**

     * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won‘t keep trying.

     * This flag disable this blacklisting.

     */

    SDWebImageRetryFailed = 1 << 0,

 

    /**

     * By default, image downloads are started during UI interactions, this flags disable this feature,

     * leading to delayed download on UIScrollView deceleration for instance.

     */

    SDWebImageLowPriority = 1 << 1,

 

    /**

     * This flag disables on-disk caching

     */

    SDWebImageCacheMemoryOnly = 1 << 2,

 

    /**

     * 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,

 

    /**

     * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.

     * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.

     * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.

     * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.

     *

     * Use this flag only if you can‘t make your URLs static with embedded cache busting parameter.

     */

    SDWebImageRefreshCached = 1 << 4,

 

    /**

     * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for

     * extra time in background to let the request finish. If the background task expires the operation will be cancelled.

     */

    SDWebImageContinueInBackground = 1 << 5,

 

    /**

     * Handles cookies stored in NSHTTPCookieStore by setting

     * NSMutableURLRequest.HTTPShouldHandleCookies = YES;

     */

    SDWebImageHandleCookies = 1 << 6,

 

    /**

     * Enable to allow untrusted SSL certificates.

     * Useful for testing purposes. Use with caution in production.

     */

    SDWebImageAllowInvalidSSLCertificates = 1 << 7,

 

    /**

     * By default, image are loaded in the order they were queued. This flag move them to

     * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which 

     * could take a while).

     */

    SDWebImageHighPriority = 1 << 8,

    

    /**

     * By default, placeholder images are loaded while the image is loading. This flag will delay the loading

     * of the placeholder image until after the image has finished loading.

     */

    SDWebImageDelayPlaceholder = 1 << 9,

 

    /**

     * We usually don‘t call transformDownloadedImage delegate method on animated images,

     * as most transformation code would mangle it.

     * Use this flag to transform them anyway.

     */

    SDWebImageTransformAnimatedImage = 1 << 10,

    

    /**

     * By default, image is added to the imageView after download. But in some cases, we want to

     * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)

     * Use this flag if you want to manually set the image in the completion when success

     */

    SDWebImageAvoidAutoSetImage = 1 << 11

};

这个文档解释的很详细,然后将options设置为SDWebImageRetryFailed(默认下载图片失败后就不会再次下载了,该选项会让下载失败的重新下载) ,解决了问题.还有其他很多选项,在相应的场合都会有用的.

SDWebImage下载图片有时候无法成功显示出来

标签:

原文地址:http://www.cnblogs.com/iqidan/p/SDWebImage_downImageCanNotShow.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!