Tap and hold save image from UIWebView

亡梦爱人 提交于 2019-12-13 04:35:42

问题


I want to be able to save an image to the photos app from a UIWebView when the user taps and holds on the image.

I've managed to save an image from a UIWebView when I was programming in objective-c however now as I'm learning swift it seems to be kind of different.

This is how I did it back in Objective-C:

-(IBAction)saveWeb:(id)sender 
{

    UIGraphicsBeginImageContext(webview.frame.size);
    [self.webview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil,nil,nil); 

}  

回答1:


The snippet you have right now is more towards taking a screen shot of the web page.

You can combine gesture recognizers and Javascript to get an image at a give point in a HTML page..

Have a look at https://stackoverflow.com/a/5607694/4236572 . You may want to implement something like that..



来源:https://stackoverflow.com/questions/31673916/tap-and-hold-save-image-from-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!