I'm working on a UIImageView inside a UIScrollView, the UIImageView is made zoomable through the UIScrollView but my goal is to get the coordinates of a point, so that whenever the user touches the UIImageView while zoomed the point "sticks" to the UIImageView, then when unzoomed (so when the zoom scale is at 1.0), the coordinates would be saved.
I was able to get the picture, put it in an ImageView in a ScrollView and I made the picture zoomable, but whenever I touch the scrollView no coordinates are being showed.
This is my code:
override func viewDidLoad() {
super.viewDidLoad()
self.scrollview.minimumZoomScale = 0.5
self.scrollview.maximumZoomScale = 6.0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func ChooseExisting(sender: AnyObject) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .PhotoLibrary
presentViewController(picker, animated: true, completion: nil)
}
@IBAction func Camera(sender: AnyObject) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .Camera
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
ChosenImage.image = info[UIImagePickerControllerOriginalImage] as? UIImage
dismissViewControllerAnimated(true, completion: nil)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return self.ChosenImage
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: (UIEvent!)) {
if let touch = touches.first as? UITouch {
let location = touch.locationInView(self.ChosenImage)
println("\(location)")
}
}
println only returns values for touches anywhere but in the ScrollView