Reputation: 239
I have a scrollview which holds an imageview, which by itself pinches and zooms just fine. My issue is when I'm programmatically adding additional imageviews to the scrollview, they are then doing the zooming and not the main scrollview. In fact, the scrollView is then "locked" for panning and zooming.
What I want to do is "sync" all the images I place on the scrollview to respond to pinch and zoom, so that everything appears in the right "scale" size at whatever zoomScale I end up with.
This is how I place new images on the screen:
let singleTapRecognizer = UITapGestureRecognizer(target: self, action: "scrollViewSingleTapped:")
singleTapRecognizer.numberOfTapsRequired = 1
singleTapRecognizer.numberOfTouchesRequired = 1
scrollView.addGestureRecognizer(singleTapRecognizer)
And this is the routine that adds the images:
imageView = UIImageView(image: UIImage(named: "Fingerprint36x36.png"))
imageView.tag = 1999
imageView.center = CGPoint(x: pointInView.x, y: pointInView.y);
scrollView.addSubview(imageView)
Once this happens, it appears that "self" becomes the new view control, and not the scrollView.
So I "think" my question is: How do I keep the gestureRecognizer focused on the ScrollView and not the "top most" imageView?
I do not have any code setup for UIPinchGestureRecognizer. It just works by default since I'm using the ScrollView.
Thanks for your help. :) Mark
Upvotes: 1
Views: 1781
Reputation: 239
OK, I figured it out and wanted to share...
In the delegate, I was reusing the same variable for my image that I was placing on the background. Changed the image name, and the issue went away by itself...
func viewForZoomingInScrollView(scrollView: UIScrollView!) -> UIView! {
return imageView
}
imageView was the name of my background at first, and then reused as the name of my xy pointer image. I was looking in the wrong place for a long time, but finally found another thread that was similar which prompted me to look at this function.
Upvotes: 2