iPhone OS: Tap status bar to scroll to top doesn't work after remove/add back

后端 未结 9 1019
执笔经年
执笔经年 2020-12-05 12:30

Using this method to hide the status bar:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

When setting \"hidden\"

相关标签:
9条回答
  • 2020-12-05 12:54

    I want to add my case, I add an UIWebView on an UIScrollView, as h4xxr had answered on the top:

    If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored

    So, I get a simply way to make it work on webView: just set the scrollView·s scrollsToTop property false.

    And when tap the status bar, it won`t got intercepted by the scrollView, and the webView scrolls to the top!

        UIScrollView *scrollView = [[UIScrollView alloc] init];
        scrollView.frame = self.view.bounds;
        scrollView.scrollsToTop = false; //igore scrollView`s scrollsToTop
        [self.view addSubview:scrollView];
    
        UIWebView *webView = [[UIWebView alloc] init];
        webView.frame = scrollView.bounds;
        [scrollView addSubview:webView];
    
    0 讨论(0)
  • 2020-12-05 12:59

    You could try setting the ScrollsToTop property to true again after re-showing it:

    [currentView setScrollsToTop:YES];
    

    If that's not working, are you definitely only showing one view? If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored...

    0 讨论(0)
  • 2020-12-05 13:00

    I just ran across a similar behavior in the app I'm currently working on. In its case, if you load a YouTube video from within a UIWebView, scroll to top stops working for the rest of the application's life cycle. I kind of assume this might happen after loading the movie player as well, but haven't confirmed. That functionality has been around a lot longer and probably has fewer bugs.

    0 讨论(0)
  • 2020-12-05 13:01

    In iOS 5.0 you can access the scrollview property of the UIWebView

    webView.scrollView.scrollsToTop = YES;
    
    0 讨论(0)
  • 2020-12-05 13:07

    The following fix by Alex worked for me. Thanks!

    ((UIScrollView *)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;
    

    Being in a hurry this fix worked great, however given more time I might've subclassed the UIWebView and accessed the protected UIScrollView member directly.

    The worry I have with Alex' method is that it assumes that UIScrollView is at index zero of the subviews (encapsulation allows private members to change). Which suggests another solution still:

    for (UIView* v in [webView subviews])
    {
        if ([v isKindOfClass:[UIScrollView class]])
        {
            (UIScrollView *)v.scrollsToTop = NO;
        }
    }
    
    0 讨论(0)
  • 2020-12-05 13:07

    When there are multiple scrollview, you can also set scrollUpToTop to NO for the others scrollview. cf:

    setScrollsToTop with multiple UIScrollView classes and/or subclasses(UITableView)

    0 讨论(0)
提交回复
热议问题