UIWebview Offset-Einstellung Problem
Frage
Ich verwende eine UIWebView (mit einer HTML-Datei geladen), und ich möchte den Versatz der gescrollt Position und der Versatz konstant bleiben sollte, wenn ich den Text size.I ändern auch die zuvor gescrollt Position gespeichert werden soll, wenn ich das ändern Textgröße . Wie dies ????
Lösung
Ich habe eine andere Methode, die ich unter http://www.alexnking.com/2008/10/14/going-back-to-the-last-place-you-were-in-a-uiwebview/ , die eine große Hilfe sein könnte, wenn Sie manuell eine UIWebView blättern möchten.
Um die aktuelle Bildlaufposition zu bringen (vertikal):
[myWebView stringByEvaluatingJavaScriptFromString: @"scrollY"];
// Application is terminating.
- (void)applicationWillTerminate:(UIApplication *)application {
[[NSUserDefaults standardUserDefaults] setInteger:
[[myWebView stringByEvaluatingJavaScriptFromString: @"scrollY"]
intValue] forKey: @"currentScroll"];
}
// Application is loading.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
initialScrollPosition = [[NSUserDefaults standardUserDefaults]
integerForKey: @"currentScroll"];
}
// WebView is finished loading
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Check if we need to scroll this somewhere.
if (initialScrollPosition != 0) {
// Scroll to the position.
[passageView stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat: @"window.scrollTo(0, %d);",
self.initialScrollPosition]];
// Set the initial scroll value to zero so we don't try
// to scroll to it again if the user navigates to another page.
self.initialScrollPosition = 0;
}
}
Andere Tipps
Für die aktuelle Offset Verwendung bekommen:
int pageYOffset = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
Für die Seite Offset Verwendung Einstellung:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d", 100]];
Für die Gesamt scrollbaren Höhe der Seite bekommen
int scrollHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];