子视图控制器无响应

时间:2016-09-07 23:14:04

标签: ios uiviewcontroller storyboard parent-child

我有一个子视图控制器(从故事板)到父视图控制器(来自.xib文件),如下所示:

enter image description here

parentViewController.m:

// creating a box for the child view controller
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat yOffset = self.view.frame.origin.y;
CGRect childBox = CGRectMake(0, screenHeight - yOffset, screenWidth, 0);

// adding the child view controller to the parent
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"child" bundle:nil];
ChildViewController *childVC = [storyboard instantiateViewControllerWithIdentifier:@"childViewController"];
childVC.view.bounds = childBox; 
// childVC.view.frame to self.view.bounds // <- this is an alternative
[self addChildViewController: childVC];
[self.view addSubview:childVC.view];

但是,结果是一个UI,其中子视图控制器中的“按钮2”完全没有响应,而父视图控制器中的“按钮1”则是。

我也尝试将“childVC.view.frame”设置为“self.view.bounds”而不是“childBox”(如上面代码中第3行到最后一行所示)和“button 2”中的子视图控制器响应,子视图控制器完全覆盖父视图控制器。

有人可以告诉我如何缩小子视图控制器,同时允许两个按钮响应用户吗?

0 个答案:

没有答案