我有两种看法。一种是包含子视图的透明视图。我只想在单击父视图时才删除screenView。单击popUpView时,我不想调用tapGesture。怎么检查?

screenView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
screenView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer * clearTable = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clearTableViewAction:)];
[clearTable setNumberOfTapsRequired:1];
[screenView setUserInteractionEnabled:YES];
[screenView addGestureRecognizer:clearTable];
screenView.tag = 100;
[self.view addSubview:screenView];

self.popUpView = [[UIView alloc]init];
self.popUpView.frame = ...
self.popUpView.backgroundColor = WhiteColor;
self.popUpView.userInteractionEnabled = YES;
self.popUpView.tag = 200;
[screenView addSubview:self.popUpView];

-(void)clearTableViewAction:(UITapGestureRecognizer*)sender {
    if(sender.view.tag == 100){
         [UIView animateWithDuration:0.2
                     animations:^{screenView.alpha = 0.0;}
                     completion:^(BOOL finished){ [screenView removeFromSuperview];
         }];
    }
}

最佳答案

使用shouldReceiveTouch委托方法并检查:

喜欢,

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view.tag == 100)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

现在,如果您单击clearTableViewAction,将不会调用popUpView手势方法。

07-28 02:36
查看更多