简体   繁体   中英

Pass pinch gesture from custom UIView to parent UIScrollView

I've got a custom UIView as a subview in a UIScrollView .

When selected , the user can resize the subview by pinching anywhere on the screen (the sub view is fairly small).

When deselected , I would like this pinch gesture to be passed on to the UIScrollView so that it can handle it as it normally does.

Here is what I'm trying.

- (IBAction)pinchInView:(UIPinchGestureRecognizer *)sender {

    if (self.item.isSelected) 
    {
        if ((sender.state == UIGestureRecognizerStateChanged) || (sender.state == UIGestureRecognizerStateEnded))
        {
            [self.item resizeWithScaleFactor:sender.scale];
        }
    } else 
    {
        [self.scrollView setZoomScale:self.scrollView.zoomScale *= sender.scale];
    }
    sender.scale = 1;
}

While it does work, it seems an awkward way to go about this.

Is there a way to let the UIScrollView handle its own zooming ?

I'm pretty much using the same approach with pan gestures as well.

If there is any way to make this less awkward, I'd really appreciate your help.

Provide a Delegate to the Gestures which You have added to subview. Implement following Method in delegate

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecoznizer shouldReceiveTouch:(UITouch *)touch{
    if(isSelected == true)
        return YES;
    else
        return NO;
    }

实现以下委托方法

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

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