当前位置:网站首页>Sdwebimage source code comb 4 # introduce several usages of existing code
Sdwebimage source code comb 4 # introduce several usages of existing code
2022-07-28 23:15:00 【Fluttering moth】
Usage examples :
BJCAImageView As UIImageView An alternative
The most common use is and UITableView Combined use of :
- - stay Interface Builder Lieutenant general UIImageView As UITableViewCell The child views ;
- - In the identification panel , Set the class name to BJCAWebImageView;
- - from bundle Set a picture as a bitmap ;
- - stay tableview:cellForRowAtIndexPath: In the method , Download the pictures url By calling setImageWithURL The method is passed in ,
Everything will be handled , From parallel download to cache management .
Asynchronous Image Downloader
It can be used independently and inherited from NSOperation Image Downloader for . Just create one BJCAWebImageDownloader example , Use its constructor :
downloader = [BJCAWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)];The download will be queued immediately ,downloadFinishedWithImage: Method will be called after the image download is completed , We need to pay attention to , It may be in a non main thread .
Asynchronous image storage
You can use singular numbers based on NSOperation Image cache storage .BJCAImageCache There is a memory cache and an optional disk cache . Disk cache writes are performed asynchronously , Not to UI Add unnecessary delays .
BJCAImageCache Class for convenience , Created a singleton method , But if you want to have your own cache namespace , You can create instances of this class by yourself .
To find cached images , have access to imageForKey: Method . If you return nil, It means that the cache does not currently own images . therefore , We need to generate and cache it . Cache key key Is the unique identification of the application of the image to be cached . It is usually the absolute of the image URL.
UIImage *cachedImage = [[BJCAImageCache sharedImageCache] imageFromKey:[url absoluteString]];By default , Image not found in cache , Will continue to look in the disk , It can also be used directly -(UIImage *)imageFromKey:(NSString *)key fromDisk:(BOOL)fromDisk; Method .
Store pictures in cache , have access to -(void)storeImage:(UIImage *)image forKey:(NSString *)key; Method .
By default , Images will be stored in memory and asynchronously on disk . If you only want memory cache, you can use -(void)storeImage:(UIImage *)image foeKey:(NSString *)key toDisk:(BOOL)toDisk; Method , take toDisk The parameter is set to NO.
边栏推荐
猜你喜欢

Thesis reading (1) - zfnet of classification

DIP-VBTV: Color Image Restoration Model Combining Deep Image Prior and Vector Bundle Total Variation

【物理应用】大气吸收损耗附matlab代码

Es personal arrangement of relevant interview questions

业界首创云原生安全检测双模型!安全狗重磅报告亮相数字中国建设峰会

can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory

The tenth improvement of yolov5: the loss function is improved to Siou

Yolov5 improvement 5: improve the feature fusion network panet to bifpn

Summary of common formula notes for solving problems in Higher Mathematics
![[radar] radar signal online sorting based on kernel clustering with matlab code](/img/56/1f8e8690b47fc4a1f101d4e530b87f.png)
[radar] radar signal online sorting based on kernel clustering with matlab code
随机推荐
Improvement 11 of yolov5: replace backbone network C3 with lightweight network mobilenetv3
Sqlilabs-1 (breakthrough record)
Leetcode exercise 3 - palindromes
Will Qualcomm and MediaTek chips soon be sold, and will they surpass Huawei to become the first in China?
Yolov5 improvement 15: network lightweight method deep separable convolution
The safety dog has been selected into many details of cloud security panorama 2.0
Learning experience sharing 5: yolov5 dataset division and Yolo format conversion
WebView whitelist
WebApplicationType#deduceFromClasspath
In 2020, the top ten domestic IC design enterprises will be exposed! These five industrial challenges still need to be overcome!
芯华章宣布完成超2亿A轮融资,全面布局EDA2.0研发
一种分布式深度学习编程新范式:Global Tensor
Leetcode 199. right view of binary tree
[copy] Internet terms, abbreviations, abbreviations
Summary of C language learning content
Wheel 7: TCP client
【MySQL系列】 MySQL表的增删改查(进阶)
Rouyi cloud platform - how to realize the launch and login functions of the project and how to create new modules
PCA learning
WebView optimization