How to find out which other UIScrollView interferes with scrollsToTop?

后端 未结 2 1208
日久生厌
日久生厌 2021-02-03 10:40

I have several view controllers with one or multiple scrollviews. Although I have explicitly set the scrollsToTop flags in view controllers with more than one scrol

相关标签:
2条回答
  • 2021-02-03 11:06

    I have used code like the following to debug this scenario, before:

    - (void)findMisbehavingScrollViews
    {
        UIView *view = [[UIApplication sharedApplication] keyWindow];
        [self findMisbehavingScrollViewsIn:view];
    }
    
    - (void)findMisbehavingScrollViewsIn:(UIView *)view
    {
        if ([view isKindOfClass:[UIScrollView class]])
        {
            NSLog(@"Found UIScrollView: %@", view);
            if ([(UIScrollView *)view scrollsToTop])
            {
                NSLog(@"scrollsToTop = YES!");
            }
        }
        for (UIView *subview in [view subviews])
        {
            [self findMisbehavingScrollViewsIn:subview];
        }
    }
    

    Depending on how many UIScrollViews you find, you can modify that code to help debug your particular situation.

    Some ideas:

    • Change the background colors of the various scrollviews to identify them on screen.
    • Print the view hierarchy of those scrollviews to identify all of their superviews.

    Ideally, you should only find a single UIScrollView in the window hierarchy that has scrollsToTop set to YES.

    0 讨论(0)
  • 2021-02-03 11:11

    I changed the accepted answers into swift for convenience:

    func findMisbehavingScrollViews() {
        var aview = UIApplication.sharedApplication().keyWindow
        findMisbehavingScrollViewsIn(aview!)
    }
    
    func findMisbehavingScrollViewsIn(aview: UIView) {
        if aview.isKindOfClass(UIScrollView) {
            if (aview as! UIScrollView).scrollsToTop {
                print("found uiscrollview \(aview)")
            }
        }
        for bview in aview.subviews {
            findMisbehavingScrollViewsIn(bview)
        }
    }
    
    0 讨论(0)
提交回复
热议问题