大家好,我的内存有问题。我尝试使用 Kingfisher将 GIF 图像显示为 UICollectionViewCell。每次我回到以前的 ViewController 并回到当前的 ViewController 时,内存都会奇怪地增长(加倍)。我将 RxSwift 与一些相关库一起使用。
这是调用 giphy api 源码,并绑定(bind)到 Collection View :
provider = RxMoyaProvider<Giphy>()
giphyTrackerModel = GiphyTrackerModel(provider: provider, gifUrl: latestGiphyName)
giphyTrackerModel
.trackGiphy()
.bindTo(collectionView.rx.items(cellIdentifier: "SearchCell", cellType: SearchCell.self)) {
(index, giphyDataModel, cell) in
cell.delegate = self
cell.giphy = giphyDataModel
}
.addDisposableTo(disposeBag)
这是我的 SearchCell.swift:
import UIKit
import Kingfisher
class SearchCell: UICollectionViewCell {
@IBOutlet weak var gifImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
gifImageView.layer.cornerRadius = 4
gifImageView.layer.masksToBounds = true
self.backgroundColor = Color.lightGray
self.layer.cornerRadius = 4
}
weak var giphy: GiphyDataModel! {
didSet {
if let gifUrl = giphy.images?.downsized?.url {
let url = gifUrl.characters.count != 0 ? URL(string: gifUrl) : URL(string: "")
gifImageView.kf.setImage(with: url)
}
}
}
}
最佳答案
尝试使用 MSStickerView 而不是 UIImageView。它应该减少一点内存使用。缓存文件也可能有问题。你应该检查一下。
关于ios - iMessage 应用程序 - 将 GIF 显示为 UICollectionViewCell 时内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098380/