简体   繁体   English

如何拍摄网站的屏幕截图

[英]How to take a screenshot of a website

I am building a web browser for iPhone in Xcode and the "home page" of my app is a speed dial page which provide 6 slots for users to add their favorite website. 我正在用Xcode构建用于iPhone的Web浏览器,我的应用程序的“主页”是快速拨号页面,该页面提供6个插槽供用户添加自己喜欢的网站。 Each slot will then display a screenshot of the website. 然后,每个插槽都会显示该网站的屏幕截图。 So what I want to do here is to grab the screenshot from the link input by users, for example, " http://www.google.com ". 因此,我在这里要做的是从用户输入的链接(例如“ http://www.google.com ”)中截取屏幕截图。 Is it possible to do this with cocoa touch? 可以通过可可粉来做到这一点吗?

In case anyone want to have a similar function like this, I did find a way to do it but not sure whether it's the best way of doing it. 如果有人想拥有类似的功能,我确实找到了一种方法,但不确定是否是最好的方法。 Or maybe now there are libraries or plugins out there that provide this function already. 也许现在已经有库或插件可以提供此功能。

My solution 我的解决方案

After users have entered a website url, you need to create a temporary UIWebView and load the url (do not make it visible to the users). 用户输入网站URL后,您需要创建一个临时UIWebView并加载该URL(不要使用户可见)。 After the UIWebView finished loading, you make the UIWebView visible and then take a screenshot, after that, make the UIWebView invisible again immediately (or simply destroy it). 在完成UIWebView的加载之后,您可以使UIWebView可见,然后进行截图,然后立即使UIWebView再次不可见(或直接销毁它)。 In this case, you will get the screenshot of that website and users won't notice what just happened. 在这种情况下,您将获得该网站的屏幕快照,并且用户不会注意到刚刚发生的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM