获取UIWebView中HTML元素的位置 [英] Getting the position of an HTML element in UIWebView

查看:71
本文介绍了获取UIWebView中HTML元素的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UIWebView装有HTML文件.我想知道加载Web视图时HTML元素在屏幕上的位置(分别为x和y坐标).

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.

预先感谢

推荐答案

您可能需要结合使用JavaScript和Objective-C才能实现此目的.您需要一个JavaScript函数来传回某些元素的屏幕位置,然后将该位置转换到iPhone的屏幕上.

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

一种方法是编写一个使用元素ID并返回其位置和屏幕分辨率的JavaScript.然后将其转换为iPhone屏幕上的Webview分辨率.但是,如果允许用户缩放和平移Web视图,则会变得更加棘手.

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.

这篇关于获取UIWebView中HTML元素的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆