iOS 手勢新增及衝突解決
例子:
設定一個背景檢視
DoModalView = [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
DoModalView.backgroundColor = [UIColorcolorWithRed:0.3green:0.3blue:0.3alpha:0.6];
新增手勢
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removesubViews)];tapGesture.delegate
[DoModalViewaddGestureRecognizer:tapGesture];
方法實現
- (void)removesubViews
{
[lockapplyTabviewremoveFromSuperview];
[DoModalViewremoveFromSuperview];
}
衝突解決(避免tabview,textfield等的手勢不響應)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch
if ([touch.view isKindOfClass:[UITextField class]])
{
return NO;
}
// 若為UITableViewCellContentView(即點選了tableViewCell),則不截獲Touch事件
if ([NSStringFromClass([touch.viewclass]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}