日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

UIWebView之获取所点位置图片URL

發(fā)布時間:2023/11/27 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIWebView之获取所点位置图片URL 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

UIWebView有自己的UIResgure,如果我們手動加入自己的GestureRecognize將不能識別,如UILongPressGestureRecongnizer. 在瀏覽網(wǎng)頁的時候,如果看到喜歡的圖片,想把它保存下來如何辦呢? 我們可以自己寫一個程序來實(shí)現(xiàn),用uiwebview開發(fā)一個自己的瀏覽器


關(guān)面說到uiwebview不能識別long press gesture,幸好有一個可以識別,那就是double click.因此我們注冊它,代碼如下:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];?
doubleTap.numberOfTouchesRequired = 2;?
[self.theWebView addGestureRecognizer:doubleTap];
然后就是實(shí)現(xiàn)doubleTap:
-(void) doubleTap :(UITapGestureRecognizer*) sender?
{?
// <Find HTML tag which was clicked by user>?
// <If tag is IMG, then get image URL and start saving>?
int scrollPositionY = [[self.theWebView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];?
int scrollPositionX = [[self.theWebView stringByEvaluatingJavaScriptFromString:@"window.pageXOffset"] intValue];?

int displayWidth = [[self.theWebView stringByEvaluatingJavaScriptFromString:@"window.outerWidth"] intValue];?
CGFloat scale = theWebView.frame.size.width / displayWidth;?

CGPoint pt = [sender locationInView:self.theWebView];?
pt.x *= scale;?
pt.y *= scale;?
pt.x += scrollPositionX;?
pt.y += scrollPositionY;?

NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", pt.x, pt.y];?
NSString * tagName = [self.theWebView stringByEvaluatingJavaScriptFromString:js];?
if ([tagName isEqualToString:@"img"]) {?
NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", pt.x, pt.y];?
NSString *urlToSave = [self.theWebView stringByEvaluatingJavaScriptFromString:imgURL];?
NSLog(@"image url=%@", urlToSave);?
}?
}
這樣我們就可以得到圖片的url,然后下載保存就行了。

轉(zhuǎn)載于:https://www.cnblogs.com/zsw-1993/archive/2012/12/17/4880565.html

總結(jié)

以上是生活随笔為你收集整理的UIWebView之获取所点位置图片URL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。