2

I'm looking for a tutorial to tell me how to create a frame to crop the photo, as the picture below

Sample

thanks

AamirR
  • 11,672
  • 4
  • 59
  • 73
  • As a first step this might help you https://stackoverflow.com/q/8460119/1244597 – AamirR Jul 19 '18 at 19:50
  • Thank you very much my friend. Put this answer, in normal response and not in comment as it solves! –  Jul 19 '18 at 20:17

1 Answers1

1

As a first step please look into implementing a UIView that resizes using the corners/handles. This post should help

Once we have a resizable UIView, then using UIView.frame's origin and size to crop the image, like so:

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)
AamirR
  • 11,672
  • 4
  • 59
  • 73