사용자가 contentView
을 누르는 경우 closeShareView
이 호출되는 것을 원하지 않습니다. modalView
에서만 어떻게 할 수 있습니까?Subview에서 UITapGestureRecognizer를 사용하지 못하도록
UIWindow* mainWindow = (((AppDelegate *)[UIApplication sharedApplication].delegate).window);
// Modal view
UIView *modalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
modalView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
// Content view (goes inside modalView)
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(modalView.center.x, modalView.center.y, 220, 220)];
[modalView addSubview:contentView];
[mainWindow addSubview:modalView];
// Tap gesture (added to modalView)
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeShareView:)];
gr.numberOfTapsRequired = 1;
[modalView addGestureRecognizer:gr];
모달을
그런 다음 같은 것을 사용 보기는 그 배경보기입니다. 사용자 상호 작용이 활성화 된 경우에도 탭은 여전히 하위보기에서 인식됩니다. – siburb
모달 뷰는 배경 뷰일뿐만 아니라 부모 뷰입니다. 부모 뷰에 제스처 인식기를 추가하면 처리 할 수 있지만 물론 작동하지 않습니다. 그래서 다른 뷰의 UIView ''(또는''UIControl''을''게으른 느낌 ''이라면''modalView''에''contentView' 뒤에 숨어 있어야합니다. – Can
나는 문자 그대로 새로운 프로젝트에 코드를 붙여 넣고 복사했다. (나 역시 놀랐다 : D). – Can