0
votes

I have a scrollview to which I have added an image view as a subview. The contentsize of the scrollview is same as the size of the imageview (width and height). There are two buttons outside the scrollview. When I click on either on them, a small rectangle view is added as a subview to the imageview. This rectangle view can be dragged anywhere on the imageview by the user after it has been added.

This works fine until I pinch to zoom the scrollview. In the viewForZoomingInScrollView: method, I return the imageview and the zooming works fine. But in the zoomed view when I try to drag around the rectangle view, it does not move. It does not recognize the pan gestures any more. Any idea why this is happening?

Thanks

Hetal

2
Is nothing happening when you try to drag the rectangle view or is the scrollView paned instead?Tobi
The scrollview is panned instead when I try dragging on the rectangle. But there is also some little portion on the rectangle where if I drag, it does drag the rectangle.Hetal Vora
Could you provide your code for setting up the scroll view, rectangle view, gesture recognizer and the pan handling method. I ran a quick test and everything works fine...Tobi
Oh wait I just realized you mentioned adding the rectangle view as subview of the UIImageView? I don't think image views are supposed to have subviews. What happens if you just add the rectangle as subview of the scrollview?Tobi
In that case, the rectangle does not zoom when I pinch to zoom. Only the imageview gets zoomed. Hence I had to add the rectangle to the image view.Hetal Vora

2 Answers

2
votes

Following up to your last comment, I'd suggest to try the following:

In your viewDidLoad method add this:

for (UIGestureRecognizer *gr in self.scrollView.gestureRecognizers) {
    if ([gr isKindOfClass:[UIPanGestureRecognizer class]])
    {
        [gr requireGestureRecognizerToFail:self.dragGR];
    }
}

where dragView is your rectangleView.

The following is probably not necessary for the above to work, but it might be good practice to clean up the view hierarchy anyway:

Add a plain UIView as superview of your image view with the same frame and add the rectangle view as subview of that new view. In your viewForZoomingInScrollView: return that new view. As I said in the comments I don't think adding subviews to UIImageViews is considered good practice. But maybe that's just my opinion :)

2
votes

This should work as well and is slightly more concise:

[self.scrollView.panGestureRecognizer requireGestureRecognizerToFail:self.myPanRecognizer];