iOS开发笔记-124:swift5 Texture ASNetworkImageNode 计算加载的图片宽高大小

img.delegate = self
        img.url = l_pic1S?.url
        img.contentMode = .scaleAspectFit

extension AddArticleCN: ASNetworkImageNodeDelegate {
   
//    func imageNode(_ imageNode: ASNetworkImageNode, didLoad image: UIImage, info: ASNetworkImageLoadInfo) {
//        imageW = CGFloat(image.cgImage?.width ?? 0)
//        imageH = CGFloat(image.cgImage?.height ?? 0)
//
//        let bgW = kScreenW - 30
//
//        imageH = imageH/imageW*bgW
//        imageW = bgW
//        bgImg.image = image
//
//        self.setNeedsLayout()
//    }
    
    func imageNode(_ imageNode: ASNetworkImageNode, didLoad image: UIImage) {
        imageW = CGFloat(image.cgImage?.width ?? 0)
        imageH = CGFloat(image.cgImage?.height ?? 0)

        let bgW = kScreenW - 30

        imageH = imageH/imageW*bgW
        imageW = bgW
//        imgData = image

        weak var weakself = self
        DispatchQueue.main.async(execute: { //主线程
            //需要在主线程设置图片,否则会在子线程出现图片没有完全加载的问题
            weakself?.bgImg.image = image
            weakself?.setNeedsLayout()
        })
    }
}

你可能感兴趣的:(iOS开发笔记-124:swift5 Texture ASNetworkImageNode 计算加载的图片宽高大小)