使用 Kingfisher 取消单个图像下载

Cancel single image download with Kingfisher

我正在使用 kingfisher 通过这些方法之一下载单个图像

KingfisherManager.shared.retrieveImage

ImageDownloader.default.downloadImage

我的问题是如何取消当前下载以便开始下一个下载?

我没有 ImageView,所以无法使用

imageView.kf.cancelDownloadTask()

这两个方法 return 一个任务对象,分别是 RetrieveImageTaskRetrieveImageDownloadTask。您需要保留 returned 的任务对象,并在您希望它取消时调用 task.cancel()