Unable to scroll vertically UIScrollView / UITableView ChildViewController if parent class UIScrollView scrolling is disabled

AIM: to achieve parent scrolling to a certain point. Freeze his scroll and let the child see the scroll to the end. Move up again, let the child see the scrolling of the controller until it reaches the top, and then let the parent view scroll until it reaches the top and the page returns to its original state.

I add any child controller like this:

- (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 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 view as child of the
//container controller 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). scrollview childviewcontroller scrollview/tableview:   - () 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;
        }
    }
}
}

CHILLDVIEW SCROLL/TABLEVIEW , , childview! ?

PS. Childroll Scroll/TableView , .

. , / !

+4

Source: https://habr.com/ru/post/1568603/


All Articles