Skip to content

Instantly share code, notes, and snippets.

@hulefei
Last active April 6, 2016 11:43
Show Gist options
  • Save hulefei/31fabd15f1a5939b4dc64637318c9257 to your computer and use it in GitHub Desktop.
Save hulefei/31fabd15f1a5939b4dc64637318c9257 to your computer and use it in GitHub Desktop.
uiwebview 获取图片URL
UILongPressGestureRecognizer *gs = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(p_gestureRecognizerAction:)];
gs.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:gs];
- (void)p_gestureRecognizerAction:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
CGPoint touchPoint = [gestureRecognizer locationInView:gestureRecognizer.view];
if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
_urlToSave = [self.webview stringByEvaluatingJavaScriptFromString:imgURL];
NSLog(@"urlToSave :%@",_urlToSave);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment