如何确定用户是否已单击UIWebView

时间:2010-10-13 17:52:24

标签: uiwebview ios

我需要获取用户点击一次后显示UIWebView的网址。

我已尝试在UIWebView下放置一个调用方法来确定网址的按钮,但这样按钮无效。我尝试在UIWebView上放一个按钮,但是这样在点击后它不会显示网址,而是提供起始网址。

请帮帮我吗?

提前致谢!

2 个答案:

答案 0 :(得分:2)

了解某人是否点击了您的观点的最佳方法是实施touchesEnded方法: 首先在viewDidLoad中声明一个带有webView大小的rect,例如:

touchRect=CGRectMake(YourWebView.startPositionX, YourWebView.StartPositionY,YourWebView.width, YourWebView.height);

然后实现touchesEnded:

(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if(touch){

        CGPoint location = [touch locationInView: [touch view]];

        if (CGRectContainsPoint(touchRect,  location)){

            //do whatever

        }
    }

}

通过这种方式,您可以了解是否在webView中进行了触摸。

答案 1 :(得分:1)

显示UIWebView的当前位置(主页的位置):

NSURLRequest* webViewRequest = [myWebView request];
if (webViewRequest) {
    NSURL* webViewURL = [webViewRequest URL];
    NSString* webViewLocation = [webViewURL absoluteString];
}