I am using a UIWebView(loaded with a HTML file) and i want the offset of the scrolled position and the offset should remain constant if i change the text size.I want to store the previously scrolled position even if i change the text Size . HOw to do this????
For getting the current Offset use :
int pageYOffset = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
For setting the page Offset use:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d", 100]];
For getting the total scrollable height of the page
int scrollHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];
Can you please let me know where to write the above code .Basically,I want to know where to detect the scrolling of webview.
int pageYOffset = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
Thanks In advance,
I have another method which i found , might be of great help, when u want to scroll UIWebView manually
To get the current scroll Position (vertical)
[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;
}
}
Hope it helps !!!