webview點擊獲取圖片

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);
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章