目的:实现父级滚动到特定点。冻结它的滚动并让子视图滚动到底部。再次向上移动,让子视图控制器滚动,直到它到达它的顶部,然后让父视图滚动直到它到达顶部并且页面进入原始状态。
我正在添加任何这样的 childviewcontroller:
- (void)switchCurrentControllerWith:(UIViewController*)viewController andViewHeight:(float)height{
//1. The current controller is going to be removed
[selectedViewController willMoveToParentViewController:nil];
// ((DRBaseViewController *)viewController).hideNavBar = YES;
//2. The new controller is a new child of the container
[self addChildViewController:viewController];
//3. Setup the new controller's frame depending on the animation you want to obtain
viewController.view.frame = containerRect;
//The transition automatically removes the old view from the superview and attaches the new controller's view as child of the
//container controller's view
[self transitionFromViewController:selectedViewController
toViewController:viewController
duration:0.1
options:UIViewAnimationOptionShowHideTransitionViews|UIViewAnimationOptionTransitionCrossDissolve
animations:^{
} completion:^(BOOL finished) {
//Remove the old view controller
[selectedViewController removeFromParentViewController];
//Set the new view controller as current
selectedViewController = viewController;
[selectedViewController didMoveToParentViewController:self];
[self.view bringSubviewToFront:navigationBar];
[self.scrollView setContentSize:CGSizeMake(320., CGRectGetMaxY(segmentedControl.frame) + height)];
}];
}
现在,有一个 UIScrollView 缩放以适应父视图控制器中的视图高度(504)。我在滚动视图委托方法中执行以下任务,以禁用父滚动视图并启用子视图控制器的滚动视图/表格视图的滚动:-(void)scrollViewDidScroll:(UIScrollView*)scrollView {
if (scrollView.contentOffset.y >= self.segmentScrollView.frame.origin.y) {
scrollView.scrollEnabled = NO;
for (UIViewController *selectedViewController in containedControllers) {
for (UIView *view in selectedViewController.view.subviews) {
if ([view isKindOfClass:[UITableView class]]) {
UITableView *tableView = (UITableView*)view;
tableView.scrollEnabled = YES;
}
else if ([view isKindOfClass:[UIScrollView class]]){
UIScrollView *scrollView = (UIScrollView *)view;
scrollView.scrollEnabled = YES;
}
}
}
}
else{
for (UIViewController *selectedViewController in containedControllers) {
for (UIView *view in selectedViewController.view.subviews) {
if ([view isKindOfClass:[UITableView class]]) {
UITableView *tableView = (UITableView*)view;
tableView.scrollEnabled = NO;
}
else if ([view isKindOfClass:[UIScrollView class]]){
UIScrollView *scrollView = (UIScrollView *)view;
scrollView.scrollEnabled = NO;
}
}
}
}
if ([scrollView isAtBottom]) {
for (UIView *view in selectedViewController.view.subviews) {
if ([view isKindOfClass:[UITableView class]]) {
UITableView *tableView = (UITableView*)view;
tableView.scrollEnabled = YES;
}
else if ([view isKindOfClass:[UIScrollView class]]){
UIScrollView *scrollView = (UIScrollView *)view;
scrollView.scrollEnabled = YES;
}
}
}
}
现在我的问题是当父级的滚动视图达到固定的内容偏移量时,子视图的滚动/表视图没有滚动,然后必须滚动子视图的滚动视图!这里似乎有什么问题?
PS。我检查了 childview 的 Scroll/TableView 的框架和内容大小,这不是问题。
注意:我看到我的子视图的表格/滚动视图的滚动已在一个方向上被禁用,而在另一个方向上被启用!