【发布时间】:2018-10-15 22:06:13
【问题描述】:
我正在开发一个具有集合视图的 iOS 应用程序。集合视图单元格(instagram 照片)的大小被配置为完美的正方形,但客户端不想要裁剪的图像,所以我试图在单元格类中创建一个完成处理程序,它将回调发送回定义的方法在我的视图控制器中,通过委托将发回我可以使用的 CGSize。
代码使用Kingfisher库下载图片
import UIKit
import Kingfisher
class InstagramPostCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
var delegate: CellResizeDelegate?
func setupForInstagramPost(_ post: InstagramPost, delegate: CellResizeDelegate) {
self.backgroundColor = UIColor.clear
self.imageView.kf_setImage(with: URL(string:post.imageURL)!)
self.imageView.clipsToBounds = true
self.imageView.contentMode = .scaleAspectFill
self.imageView.backgroundColor = UIColor.clear
self.imageView.tintColor = UIColor.clear
self.delegate = delegate
}
}
我检查了这一行的定义:
self.imageView.kf_setImage(with: URL(string:post.imageURL)!)
发现它接受了一个完成处理程序:
public func kf_setImage(with resource: Resource?, placeholder: Image? = default, options: KingfisherOptionsInfo? = default, progressBlock: Kingfisher.DownloadProgressBlock? = default, completionHandler: Kingfisher.CompletionHandler? = default) -> Kingfisher.RetrieveImageTask
如何在 InstagramPostCell 类中定义自定义完成处理程序以使用委托将新下载的图像的 CGSize 发送回视图控制器?
我希望这是有道理的
谢谢, T
【问题讨论】: