无法将 UIWebView 移动到 iOS11 (iPad) 中的指定部分
Unable to move UIWebView to a specified section in iOS11 (iPad)
我们使用以下代码行移动到网络视图:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#-1\';"]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#%@\';", index]];
但不知何故此代码仅在 iPad 中不起作用。这是我初始化网络视图的方式:
webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView setDelegate:self];
[webView.scrollView setDelegate:self];
[webView setBackgroundColor:WHITECOLOR];
[webView setScalesPageToFit:YES];
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview: webView];
谁能指导我如何调试它。
In iOS11 location.hash
似乎被破坏了,但这是一个简单的解决方案。
而是使用通常的组合:
location.hash = "";
location.hash = _some_hash_string_
使用下面的javascript:
var hashElement=document.getElementsByName(_some_hash_string_)[0];
if(hashElement) {
hashElement.scrollIntoView();
} else {
// if the element is not found - scroll to top
document.documentElement.scrollIntoView();
}
我们使用以下代码行移动到网络视图:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#-1\';"]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#%@\';", index]];
但不知何故此代码仅在 iPad 中不起作用。这是我初始化网络视图的方式:
webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView setDelegate:self];
[webView.scrollView setDelegate:self];
[webView setBackgroundColor:WHITECOLOR];
[webView setScalesPageToFit:YES];
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview: webView];
谁能指导我如何调试它。
In iOS11 location.hash
似乎被破坏了,但这是一个简单的解决方案。
而是使用通常的组合:
location.hash = "";
location.hash = _some_hash_string_
使用下面的javascript:
var hashElement=document.getElementsByName(_some_hash_string_)[0];
if(hashElement) {
hashElement.scrollIntoView();
} else {
// if the element is not found - scroll to top
document.documentElement.scrollIntoView();
}