gpt4 book ai didi

ios - 翠鸟图像在加载前是否已调整大小?

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

我使用以下命令将图像加载到tableview中:

        let imageSize: CGFloat = 125.0
let processor = RoundCornerImageProcessor(cornerRadius: 10)
let placeholder = UIImage(color: .gray, size: CGSize(width: imageSize, height: imageSize))

cell.imageView?.kf.indicatorType = .activity
cell.imageView?.kf.setImage(with: url!, placeholder: placeholder, options: [.transition(.fade(0.2)), .processor(processor)])
cell.imageView?.layer.masksToBounds = true
cell.imageView?.clipsToBounds = true
cell.imageView?.contentMode = .scaleAspectFill

虽然看起来发生的情况是,图像比设置的大小(125.0)大一秒,然后在加载后正确调整大小。我假设它取tableView单元格的大小,即:
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}

尽管如此,我只需要我的图像一直是125.0。有什么帮助吗?

最佳答案

这可能对你有帮助

    cell.imageView?.contentMode = .scaleAspectFit
class func ResizeImage(image: UIImage, targetSize: CGSize) -> UIImage
{
let size = image.size

let widthRatio = targetSize.width / image.size.width
let heightRatio = targetSize.height / image.size.height

// Figure out what our orientation is, and use that to form the rectangle
var newSize: CGSize
if(widthRatio > heightRatio) {
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
} else {
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
}
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRect(x: 0, y: 0, width: newSize.width,height: newSize.height)

// Actually do the resizing to the rect using the ImageContext stuff
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return newImage!
}

关于ios - 翠鸟图像在加载前是否已调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51679160/

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