最佳答案
作为第一步,请考虑实现一个使用角/ handle 调整大小的 UIView
。这post应该有帮助
一旦我们有了可调整大小的 UIView
,然后使用 UIView.frame
的原点和大小来裁剪图像,如下所示:
extension UIImage {
func crop(size: CGSize, offset: CGPoint, scale: CGFloat = 1.0) -> UIImage? {
let rect = CGRect(x: offset.x * scale, y: offset.y * scale, width: size.width * scale, height: size.height * scale)
if let cropped = self.cgImage?.cropping(to: rect) {
return UIImage(cgImage: cropped)
}
return nil
}
}
let croppedImage = image.crop(size: resizableView.frame.size, offset: resizableView.frame.origin)
关于Swift:用于 UIImageView 的 CropView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51430615/