在当前视图上添加子视图后 UIButton 不工作

UIButton is not working after adding Subview on present view

我有一个带有一些按钮的 ViewController1(notificationVC),我想将此 VC1 的视图插入到另一个 VC2(infoView)。

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    NotificationVC *notificationVC = [[NotificationVC alloc]initWithNibName:@"NotificationVC" bundle:nil];
    notificationVC.view.frame = CGRectMake(0, _infoView.frame.size.height-425,[UIScreen mainScreen].bounds.size.width, 400);
    [_infoView addSubview:notificationVC.view];
}

此代码可以很好地显示视图,但问题是,显示它后 UIButton 不起作用。

这是因为通知 VC 应该处理 ViewController 中的手势。要实现这些,请添加 ViewController as child

[_infoView addSubview:notificationVC.view];
[self addChildViewController: notificationVC];

别忘了删除它