我有parentView
和 subView childView
。
childView
位于我的中间,parentView
大约是它的一半大小。
我想childView
在用户点击时关闭parentView
。
我的代码如下UITapGestureRecognizer
在打开parentView
后创建一个childView
。
我的问题是当用户触摸任何视图时触发点击事件,而不仅仅是parentView
.
因此,我想知道如果只有 parentView 被触摸或任何其他可能关闭子视图的父视图被触摸,我如何才能使事件发生。
- (IBAction)selectRoutine:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
createRoutinePopupViewController* popupController = [storyboard instantiateViewControllerWithIdentifier:@"createRoutinePopupView"];
popupController.view.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
_ass = popupController;
//Tell the operating system the CreateRoutine view controller
//is becoming a child:
[self addChildViewController:popupController];
//add the target frame to self's view:
[self.view addSubview:popupController.view];
//Tell the operating system the view controller has moved:
[popupController didMoveToParentViewController:self];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singleTap setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:singleTap];
}
-(void) handleSingleTap: (id) sender {
NSLog(@"TEST STRING");
}