我使用一个UIWebView(装有一个HTML文件),我想偏移的滚动位置和偏移量应保持不变,如果我改变文字size.I要存储先前滚动位置,即使如果我更改文字大小。这个怎么做????UIWebView的偏移设置问题
3
A
回答
2
我总滚动高度另一种方法,我发现在http://www.alexnking.com/2008/10/14/going-back-to-the-last-place-you-were-in-a-uiwebview/,当你想SC可能有很大的帮助手动滚动UIWebView。
要获取当前的滚动位置(垂直):
[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;
}
}
希望它可以帮助!
3
获取当前偏移使用:
int pageYOffset = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
对于设置页面偏移使用:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d", 100]];
1
用于获取页面
int scrollHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];
相关问题
- 1. 如何设置的UIWebView起始偏移
- 2. Jquery偏移问题
- 3. PyOpenGL:glVertexPointer()偏移问题
- 4. jQuery:偏移问题
- 5. JQuery的偏移问题
- 6. Gnuplot 4.4轴偏移问题
- 7. StackView插入偏移问题
- 8. JQuery偏移量问题
- 9. 设置ScrollView的内容偏移量
- 10. 如何设置到PHAsset.fetchAssets的偏移量?
- 11. Firefox中的SVG偏移问题
- 12. UITableView的内容偏移-64pt问题
- 13. 问题的UIWebView
- 14. UIWebView的问题
- 15. jQuery偏移问题:不改变SWF的位置
- 16. PHP未设置+未定义偏移
- 17. 在jQuery中设置偏移量
- 18. 在PHP中设置时区偏移量
- 19. php:通过UTC偏移设置时区
- 20. 如何为RichMarker设置偏移量?
- 21. jquery ie8 scrollTop和偏移问题
- 22. iPhone用户界面偏移问题
- 23. 使用RotateTransform问题与偏移
- 24. will_paginate和“晚排偏移”问题
- 25. 问题用2 DIV稍微偏移
- 26. PHP数组问题 - 未定义偏移
- 27. 另一个excel偏移问题
- 28. PySide QPainter.drawRect()与QBrush偏移问题
- 29. jquery.serialScroll偏移问题(图片对齐)
- 30. 问题NumberPicker图像显示偏移
我想你应该归功于来源:http://www.alexnking.com/2008/10/14/going-back-to-the-last-place-you-were-in-a-uiwebview/ – 2010-09-14 17:10:31
对不起汤米,我会记住这一点在下一次 – RVN 2010-09-14 18:24:08