Status bar detects taps only when the UIWebView is

2019-06-02 18:17发布

I have a UIWebView as the root view of a UINavigationController. When a webpage finishes to load, I hide the navigation bar, and I'm looking for a way to show it back. Right now, I'm trying to do that when the user taps the status bar (this approach looks to me more complicated than what I want).

In order to accomplish this, firstly I get the scrollView of the webView:

for (id subview in mainWebView.subviews) {
    if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
        ((UIScrollView *)subview).delegate = self;
    }
}

and then I use the delegate method:

-(BOOL) scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    return NO;
}

I was hoping that this would work, but here is what happens:

  • Page loads, and navigation bar gets hidden (that's good)
  • I try to tap the status bar, but nothing happens (that's bad)
  • I scroll down so that the webview is "far" from the status bar
  • Without letting the webview go, I tap the status bar with another finger and it works! (that's weird :)

Soooo, any help regarding that? Why is this happening?

2条回答
2楼-- · 2019-06-02 18:29

I had same problem. I solved it by :

[[[webView subviews] objectAtIndex:0] setScrollsToTop:NO];

Also you can get access scrollView property in iOS 5 by :

webView.scrollView.scrollsToTop = NO ;
查看更多
The star\"
3楼-- · 2019-06-02 18:31

I just tried this again in iOS 5.0 and it seems to work as expected:

[self.webView.scrollView setDelegate:self];
[self.webView.scrollView setScrollsToTop:YES];

and then:

-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
查看更多
登录 后发表回答