简体   繁体   中英

On zoom, UIScrollview subviews not recognizing gesture

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

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 :)

这也应该工作,并且更加简洁:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM