I have the following UI hierarchy:
UIView -> UIScrollView -> UIImageView
It was necessary because i wanted to zoom my image in and out. So far so good and everything works. Now i wanted to detect the touch location of the image. I've read already a lot and it works if i just have an UIImage in an UIView. Unfortunately i need it for the first described hierarchy.
class TestController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet var myGestureRecognizer: UITapGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
self.myImageView.addGestureRecognizer(myGestureRecognizer)
myImageView.userInteractionEnabled = true
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject()! as UITouch
let location = touch.locationInView(self.myImageView)
println(location)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return self.myImageView
}
.....
}
I've tried to add "myGestureRecognizer" to UIView and also to the UIImageView and even to all 3 (UIView, UIScrollView, UIImageView) together. It just doesn't work for me and I don't know what to do.
How can I detect the location of touches (just single tap) in a UIImageView, which is placed in a UIScrollView?
Thanks in advance!