-2

This is what I'd like to achive in Xcode/swift:

I want to create a blank "canvas" at a fixed size, ex. 300x300px. I want to add a picture to the canvas and the picture should be zoomable (pinch to zoom) within the boundaries of the canvas.

Finally when the preferred zoom/crop is set, I want to save the crop in the 300x300px size canvas.

Anyone who has a solution to this and is this in any way possible? Greatly appreciated.

jscs
  • 63,694
  • 13
  • 151
  • 195
gotfunk
  • 39
  • 6

1 Answers1

0

Like this answer said, use UIPinchGestureRecognizer and UIImage's scale property.

override func viewDidLoad() {
    let pinch = UIPinchGestureRecognizer(target: self, action: "pinchImage:")
    self.view.addGestureRecognizer(pinch)
}

@IBOutlet weak var imgView: UIImageView!

func pinchImage(sender: UIPinchGestureRecognizer) {
    if sender.state == .Ended {
        if sender.scale < 1.0 {
            sender.scale = 1.0
        }
        self.imgView.transform = CGAffineTransformMakeScale(sender.scale, sender.scale)
    }
}
Community
  • 1
  • 1
brimstone
  • 3,370
  • 3
  • 28
  • 49