Objective c 如何在ios中从uiwebview获取图像

Objective c 如何在ios中从uiwebview获取图像,objective-c,ios,uiwebview,uiimageview,nsurl,Objective C,Ios,Uiwebview,Uiimageview,Nsurl,在这里,我在webview中加载了内容和图像,我想从webview中获取图像并将其加载到imageview中 已接收图像的url,但未将图像加载到imageview 这里我使用的代码是从webview获取图像 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //Touch gestures below top bar should

在这里,我在webview中加载了内容和图像,我想从webview中获取图像并将其加载到imageview中

已接收图像的url,但未将图像加载到imageview

这里我使用的代码是从webview获取图像

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    //Touch gestures below top bar should not make the page turn.
    //EDITED Check for only Tap here instead.
    if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
        CGPoint touchPoint = [touch locationInView:self.view];

        NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"];
        NSLog(@"pageFlag tapbtnRight %d", pageFlag);

        if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
  NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
            NSString *urlToSave = [webView stringByEvaluatingJavaScriptFromString:imgURL];
            NSLog(@"urlToSave :%@",urlToSave);
}
}
看看这个

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(@"TAPPED");
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
    CGPoint touchPoint = [touch locationInView:self.view];

    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"];
    NSLog(@"pageFlag tapbtnRight %d", pageFlag);

    if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
        NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
        NSString *urlToSave = [webV stringByEvaluatingJavaScriptFromString:imgURL];
        NSLog(@"urlToSave :%@",urlToSave);
        NSURL * imageURL = [NSURL URLWithString:urlToSave];
        NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
        UIImage * image = [UIImage imageWithData:imageData];
        imgView.image = image;//imgView is the reference of UIImageView
    }
  }
return YES;
}
示例代码:

@Psycholidad你有没有想到如何让它适用于谷歌图像?我告诉用户点击查看图像按钮。我认为OP希望直接从加载的
UIWebView
获取图像,而不是再次下载