状态栏仅在 UIWebView 向下滚动时检测点击 [英] Status bar detects taps only when the UIWebView is scrolled down a bit
问题描述
我有一个 UIWebView
作为 UINavigationController
的根视图.当网页完成加载时,我隐藏了导航栏,并且我正在寻找一种将其显示回来的方法.现在,当用户点击状态栏 (这种方法在我看来比我想要的更复杂).
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).
为了实现这一点,首先我得到了 webView 的 scrollView:
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;
}
}
然后我使用委托方法:
-(BOOL) scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
[self.navigationController setNavigationBarHidden:NO animated:YES];
return NO;
}
我希望这会奏效,但结果是这样的:
I was hoping that this would work, but here is what happens:
- 页面加载,导航栏隐藏(很好)
- 我尝试点按状态栏,但没有任何反应(这很糟糕)
- 我向下滚动,使 webview 离状态栏很远"
- 在不放开 webview 的情况下,我用另一个手指点击状态栏,它就可以工作了!(这很奇怪:)
Soooo,对此有什么帮助吗?为什么会发生这种情况?
Soooo, any help regarding that? Why is this happening?
推荐答案
我刚刚在 iOS 5.0 中再次尝试了这个,它似乎按预期工作:
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];
然后:
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
这篇关于状态栏仅在 UIWebView 向下滚动时检测点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!