Setting ImageRequestOptions.normalizedCropRect (in swift)

Setting ImageRequestOptions.normalizedCropRect (in swift)



self.imageRequestOptions.resizeMode = .exact

let assetWidth = CGFloat(self.asset.pixelWidth)
let assetHeight = CGFloat(self.asset.pixelHeight)
let cropLength = assetWidth < assetHeight ? assetWidth : assetHeight

let cropWidthRatio = cropLength / assetWidtha
let cropHeightRatio = cropLength / assetHeight
let cropRect = CGRect(x: (1 - cropWidthRatio) / 2, y: (1 - cropHeightRatio) / 2, width: cropWidthRatio, height: cropHeightRatio)

self.imageRequestOptions.normalizedCropRect = cropRect

ImageCell.imageManager.startCachingImages(for: [asset], targetSize: ImageCell.cellSize, contentMode: .default, options: self.imageRequestOptions)

Comments