gpt4 book ai didi

ios - 如何在调用触摸手势事件时检查其父 View 或 subview ?

转载 作者:行者123 更新时间:2023-11-29 11:54:13 24 4
gpt4 key购买 nike

我有两种看法。一种是包含 subview 的透明 View 。我只想在单击父 View 时删除 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委托(delegate)方法并检查:

喜欢,

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

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

关于ios - 如何在调用触摸手势事件时检查其父 View 或 subview ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39803390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com