代码之家  ›  专栏  ›  技术社区  ›  Knodel

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

  •  1
  • Knodel  · 技术社区  · 15 年前

    我需要得到一个 UIWebView 在用户单击一次后显示。

    我试过在 ,但这样按钮就不起作用了。我试着把一个按钮放在 UIWebView网站 但这样它就不会给出点击后的url,而是给出起始url。

    你能帮帮我吗?

    提前谢谢!

    2 回复  |  直到 12 年前
        1
  •  2
  •   JonLOo    15 年前

    要知道是否有人单击了您的视图,最好的方法是实现touchesend方法: 首先声明一个rect,它的大小与viewDidLoad中的webView相同,例如:

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

    然后实现toucheSend:

    (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
    
            }
        }
    
    }
    

        2
  •  1
  •   Mihnea Ovidenie    15 年前

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

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