gpt4 book ai didi

ios - 带完成 block 的 SDWebImage 预取

转载 作者:行者123 更新时间:2023-11-28 07:55:44 26 4
gpt4 key购买 nike

我的目标是用“加载屏幕”覆盖 collectionView,在 SDWebImage 将预取图像数组中的所有图像加载到缓存中之前,该屏幕不会隐藏。

在我的 viewDidLoad 中,我检索了一组图像 URL,这些图像 URL 将用于填充 Collection View 。检索到它们后,我计划使用 SDWebImagePrefetcher 来处理数组。

到目前为止,我有以下内容:

let urls : [URL] = [URL(string: "https://trialwebsite.com/image1.png")!,URL(string: "https://trialwebsite.com/image2.png")!,URL(string: "https://trialwebsite.com/image3.png")!]

SDWebImagePrefetcher.shared().prefetchURLs(urls)

我正在努力弄清楚的是,一旦处理完所有图像,如何使用完成 block 隐藏“加载”屏幕。

非常感谢任何帮助。

最佳答案

你可以使用 prefetchURLs:completed:而不是使用 prefetchURLs,它会有一个包含 finishedCountskippedCount 无符号整数的完成 block (关闭,因为你正在编写 Swift):

如方法文档中所述:

completionBlock

block to be called when prefetching is completed

这似乎是你想要的。所以它会是这样的:

SDWebImagePrefetcher.shared().prefetchURLs(urls) { finishedCount, skippedCount in
// hide the 'loading' screen...
// you might need to implement your own counting logic
// to make sure that all images have been processed.
}

关于ios - 带完成 block 的 SDWebImage 预取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48121378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com