从 UIWebView 点击并按住保存图像 [英] Tap and hold save image from UIWebView
问题描述
当用户点击并按住图像时,我希望能够将图像从 UIWebView
保存到照片应用.
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.
当我在 Objective-c 中编程时,我已经设法从 UIWebView
保存图像,但是现在我正在快速学习它似乎有点不同.
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.
这就是我在 Objective-C 中的做法:
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);
}
推荐答案
您现在拥有的代码片段更倾向于截取网页的屏幕截图.
The snippet you have right now is more towards taking a screen shot of the web page.
您可以结合手势识别器和 Javascript 来获取 HTML 页面中给定点的图像..
You can combine gesture recognizers and Javascript to get an image at a give point in a HTML page..
查看 https://stackoverflow.com/a/5607694/4236572.你可能想要实现类似的东西..
Have a look at https://stackoverflow.com/a/5607694/4236572 . You may want to implement something like that..
这篇关于从 UIWebView 点击并按住保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!