Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 触摸父视图时关闭子视图_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 触摸父视图时关闭子视图

Ios 触摸父视图时关闭子视图,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有parentView和子视图childView。 子视图位于我的代码> PaleVIEW < /C>中间,大约是它的一半大小。 当用户点击父视图时,我想关闭子视图 打开子视图后,我的代码如下所示在父视图中创建一个uitappesturerecognizer 我的问题是,当用户触摸任何视图时会触发点击事件,而不仅仅是父视图 因此,我想知道,如果仅触摸父视图,我如何才能使事件发生,或者如果触摸父视图,如何关闭子视图 - (IBAction)selectRoutine:(id)sender {

我有
parentView
和子视图
childView
。 <代码>子视图<代码>位于我的代码> PaleVIEW < /C>中间,大约是它的一半大小。

当用户点击父视图时,我想关闭子视图

打开
子视图后,我的代码如下所示在
父视图
中创建一个
uitappesturerecognizer

我的问题是,当用户触摸任何视图时会触发点击事件,而不仅仅是
父视图

因此,我想知道,如果仅触摸父视图,我如何才能使事件发生,或者如果触摸父视图,如何关闭子视图

- (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");
}

您需要使用UIgestureRecognitizerDelegate,实现以下方法

它将检查触摸视图

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if( [touch view] != popupController.view)
        return YES;

    return NO;
}

它说objView是未定义的?显然它应该说,因为您需要用父视图的object替换它。希望您在头文件中添加了object,并且还指定了singleTap.delegate=self;我这样做了,它永远不会回来是的。我把代码放在parentView文件中。尝试选择父视图和子视图,但始终返回添加UIGestureRecognitizerDelegate的noI