简体   繁体   English

无法将UIWebView移动到iOS11(iPad)中的指定部分

[英]Unable to move UIWebView to a specified section in iOS11 (iPad)

We have used the below lines of code to move to the web view: 我们已使用以下代码行将其移至Web视图:

[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#-1\';"]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.location.hash=\'#%@\';", index]];

but somehow this code doesn't work only in iPad. 但是以某种方式,此代码仅在iPad中不起作用。 Here is how I initialised the web view: 这是我初始化网络视图的方式:

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];

Could someone please guide me how to debug it. 有人可以指导我如何调试它。

In iOS11 location.hash seems to be broken, but it's a simple solution to this. 在iOS11中, location.hash似乎已损坏,但这是一个简单的解决方案。 Instead using an usual combination: 而是使用通常的组合:

location.hash = "";
location.hash = _some_hash_string_

use javascript below: 使用下面的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(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM