有谁知道如何使用 swift中的代码(不是屏幕,因为webview很长,我们必须滚动查看所有内容)并通过UIActivityViewController共享它,我可以为我的所有Web视图拍摄完整的屏幕截图? 加载Web视图后,请
编辑:在模拟器中运行此代码,然后检查文档应用程序目录中的screenshot.jpeg文件
class ViewController: UIViewController,UIWebViewDelegate { let fileDirectory = NSSearchPathForDirectoriesInDomains( .DocumentDirectory, .UserDomainMask, true) @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { var urlPath = "http://www.bbc.com/" let requestUrl = NSURL(string: urlPath) let request = NSURLRequest(URL: requestUrl!) webView.loadRequest(request) webView.delegate = self } func webViewDidFinishLoad(webView: UIWebView) { if (!webView.loading){ var webViewFrame = webView.frame webView.frame = CGRectMake(webViewFrame.origin.x, webViewFrame.origin.y, webView.scrollView.contentSize.width, webView.scrollView.contentSize.height) UIGraphicsBeginImageContextWithOptions(webView.scrollView.contentSize, false, 0); self.webView.layer.renderInContext(UIGraphicsGetCurrentContext()) var image:UIImage = UIGraphicsGetImageFromCurrentImageContext(); var imageData = UIImageJPEGRepresentation(image, 0.7) var currentFileName = "screenshot.jpeg" var imageFilePath = fileDirectory[0].stringByAppendingPathComponent(currentFileName) var imageFileURL = NSURL(fileURLWithPath: imageFilePath) imageData.writeToURL(imageFileURL!, atomically: false) webView.frame = webViewFrame } } }