Ios 从UIPinchGestureRecognizer排除子视图

Ios 从UIPinchGestureRecognizer排除子视图,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有一个子视图重叠在超级视图的顶部。子视图有4个按钮,需要可点击。superview具有缩放视图的收缩缩放手势。但是我想禁用子视图上的缩放。 识别器也在子视图中启动,有没有办法将识别器从子视图中排除?我使用了下面的简单方法: UIView *superview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480); UIView *subview = [[UIView alloc] initWithFrame:CG

我有一个子视图重叠在超级视图的顶部。子视图有4个按钮,需要可点击。superview具有缩放视图的收缩缩放手势。但是我想禁用子视图上的缩放。
识别器也在子视图中启动,有没有办法将识别器从子视图中排除?

我使用了下面的简单方法:

    UIView *superview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
    UIView *subview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
    UIPanGestureRecognizer *recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @selector(handlePinch);
    superview.userInteractionEnabled = YES;
    subview.userInteractionEnabled = YES;
    [superview addGestureRecognizer:recognizer];

这可能不是最好的选择,但这也能奏效吗?其他StackOverflow用户请友好,我是新手

     UIView *superview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
superview.tag=1; //set Tag for superview

    UIView *subview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
subview.tag==2; //set Tag for subview
    UIPanGestureRecognizer *recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @selector(handlePinch);
    superview.userInteractionEnabled = YES;
    subview.userInteractionEnabled = YES;
    [superview addGestureRecognizer:recognizer];


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

    if(touch.view .tag==2) //if subview is touched then disable pinch gesture.
    {
        return NO;

    }
    return YES;
}
包含CGRectContainsPoint的Apple文档


您不能,因为如果在子视图上排除手势识别器或用户交互,这将影响superview,因为两个视图的帧大小相同,并且子视图与superview完全重叠
     UIView *superview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
superview.tag=1; //set Tag for superview

    UIView *subview = [[UIView alloc] initWithFrame:CGRectMake:(0, 0, 320, 480);
subview.tag==2; //set Tag for subview
    UIPanGestureRecognizer *recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @selector(handlePinch);
    superview.userInteractionEnabled = YES;
    subview.userInteractionEnabled = YES;
    [superview addGestureRecognizer:recognizer];


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

    if(touch.view .tag==2) //if subview is touched then disable pinch gesture.
    {
        return NO;

    }
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
 shouldReceiveTouch:(UITouch *)touch
{
    CGPoint touchPoint = [gestureRecognizer locationInView: superview];

    if(CGRectContainsPoint(subview.frame, touchPoint)
    {
         return NO;
    }
    return YES;
}