The child viewController gesture is intercepted by the parent viewController

if you add the addChildViewController sub-viewController, there is still no response

< hr >
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 200, 60, 60)];
    [btn setTitle:@"" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:btn];
    
    [self addChildViewController:self.imgVC];
    
}

- (void)btnClick{
    NSLog(@"");
    
}
// 
- (addImgVC *)imgVC{
    if (!_imgVC) {
        _imgVC = [[addImgVC alloc]init];
        [_imgVC.view setFrame:CGRectMake(0, 50, 375, 62)];
        [self.view addSubview:_imgVC.view];
        
    }
    return _imgVC;
}
Nov.24,2021

your call flow is still not clear, just write your [self.view addSubview:self.imgVC.view] in addChildViewController . Because when you load lazily, the process you write is to add view , and then add sub-controllers. However, the correct process is to add sub-controllers before you can add view

.
Menu