Getting the position of an HTML element in UIWebView

梦想与她 提交于 2019-12-22 18:09:41

问题


I have UIWebView loaded with an HTML file. I want to know the position (means x and y cordinates) of an HTML element on the screen when the webview is loaded.

Thanks in advance


回答1:


You may need to a combination of JavaScript and Objective-C to achieve this. You need a JavaScript function to pass back the screen position of certain element, and then translate that position to the screen on the iPhone.

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

One way is to write a JavaScript that takes an element ID and returns its position and the screen resolution. Then translate that to the webview resolution on iPhone screen. It gets trickier if the user is allowed to zoom and pan the webview though.



来源:https://stackoverflow.com/questions/3360139/getting-the-position-of-an-html-element-in-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!