gpt4 book ai didi

uiwebview - 如何确定用户是否点击了 UIWebView

转载 作者:行者123 更新时间:2023-12-01 19:29:06 28 4
gpt4 key购买 nike

我需要获取 UIWebView 的 url在用户单击一次后显示。

我尝试在 UIWebView 下放置一个按钮,该按钮调用确定 url 的方法。 ,但这样按钮不起作用。我试过在 UIWebView 上放一个按钮但这种方式它提供的不是点击后的网址,而是起始网址。

你能帮我吗?

提前致谢!

最佳答案

了解是否有人点击了您的 View 的最佳方法是实现 touchesEnded 方法:
首先在 viewDidLoad 中声明一个具有 webView 大小的矩形,例如:

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 中进行了触摸。

关于uiwebview - 如何确定用户是否点击了 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3926479/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com