我需要获取用户点击一次后显示UIWebView
的网址。
我已尝试在UIWebView
下放置一个调用方法来确定网址的按钮,但这样按钮无效。我尝试在UIWebView
上放一个按钮,但是这样在点击后它不会显示网址,而是提供起始网址。
请帮帮我吗?
提前致谢!
答案 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];
}