How to Make the scroll of a TableView inside ScrollView behave naturally

后端 未结 13 2074
无人及你
无人及你 2020-12-07 08:22

I need to do this app that has a weird configuration.

As shown in the next image, the main view is a UIScrollView. Then inside it should have a UIPageView, and each

13条回答
  •  甜味超标
    2020-12-07 08:52

    I think there are two options.

    Since you know the size of the scroll view and the main view, you are unable to tell whether the scroll view hit the bottom or not.

    if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
        // reach bottom
    }
    

    So when it hit; you basically set

    [contentScrollView setScrollEnabled:NO];
    

    and other way around for your tableView.

    The other thing, which is more precise I think, is to add Gesture to your views.

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
    initWithTarget:self action:@selector(respondToTapGesture:)];
    
    // Specify that the gesture must be a single tap
    tapRecognizer.numberOfTapsRequired = 1;
    
    // Add the tap gesture recognizer to the view
    [self.view addGestureRecognizer:tapRecognizer];
    
    // Do any additional setup after loading the view, typically from a nib
    

    So when you add Gesture, you can simply control the active view by changing setScrollEnabled in the respondToTapGesture.

提交回复
热议问题