我将一个NavigationController作为子VC放在ScrollView上。这是代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = YES;
_scrollView = [UIScrollView newAutoLayoutView];
_scrollView.alwaysBounceVertical = YES;
_scrollView.delaysContentTouches = NO;
[self.view addSubview:_scrollView];
[_scrollView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
_contentView = [UIView newAutoLayoutView];
UIView *yellowView = [UIView newAutoLayoutView];
yellowView.backgroundColor = [UIColor yellowColor];
[_contentView addSubview:yellowView];
[yellowView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[yellowView autoSetDimensionsToSize:CGSizeMake(kScreenWidth, kScreenHeight)];
[_scrollView addSubview:_contentView];
_settingsNavigationController = [UINavigationController new];
[self addChildViewController:_settingsNavigationController];
[_contentView addSubview:_settingsNavigationController.view];
[_settingsNavigationController didMoveToParentViewController:self];
[_settingsNavigationController.view autoSetDimensionsToSize:CGSizeMake(kScreenWidth, kScreenHeight)];
[_settingsNavigationController.view autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:yellowView];
[_settingsNavigationController.view layoutSubviews];
[_contentView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:_settingsNavigationController.view];
[_contentView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[_contentView autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:self.view];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
PCConfigViewController *configViewController = [PCConfigController new];
configViewController.morning = YES;
configClockViewController.delegate = self;
[_settingsNavigationController setViewControllers:[NSArray arrayWithObject:configViewController] animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
我可以滚动到NavigationController并查看其根视图控制器,但它不响应触摸,即使NavigationController被添加为子视图控制器。任何想法,或如何使其响应触摸?