【发布时间】:2016-10-01 05:37:04
【问题描述】:
我有两种看法。一种是包含子视图的透明视图。我只想在单击父视图时删除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];
}];
}
}
【问题讨论】:
-
如果将 userInteractionEnabled 设为 NO。 TapGesture 仍然被调用。
标签: ios objective-c uiview uitapgesturerecognizer