Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:如何将整个可滚动的UITableVIew保存为PNG_Ios_Swift_Uitableview_Uiscrollview_Png - Fatal编程技术网

Ios Swift:如何将整个可滚动的UITableVIew保存为PNG

Ios Swift:如何将整个可滚动的UITableVIew保存为PNG,ios,swift,uitableview,uiscrollview,png,Ios,Swift,Uitableview,Uiscrollview,Png,我想将整个UITableView保存为PNG文件 使用此代码,我成功地保存了可见部分: UIGraphicsBeginImageContextWithOptions(tableView.layer.frame.size, false, 0.0); tableView.layer.renderInContext(UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext() UIGrap

我想将整个UITableView保存为PNG文件

使用此代码,我成功地保存了可见部分:

UIGraphicsBeginImageContextWithOptions(tableView.layer.frame.size, false, 0.0);
tableView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let data = UIImagePNGRepresentation(image)
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let imageURL = documentsURL.URLByAppendingPathComponent("cached.png")
data!.writeToURL(imageURL, atomically: false)
但我也想滚动的部分,目前还没有显示

有什么想法吗?

以下是一些可以添加到项目中以制作屏幕截图的内容:

新守则将是:

let image = tableView.screenshot
let data = UIImagePNGRepresentation(image)
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let imageURL = documentsURL.URLByAppendingPathComponent("cached.png")
data!.writeToURL(imageURL, atomically: false)

你怎么能截屏一些根本没有在屏幕上呈现的东西呢?不过很有趣。也许在一路截图的同时以编程方式滚动它?是的,但这是我能提供的全部。它有多大?你能同时在内存中加载所有内容吗?我会滚动到最后一个可见单元格+1(如果存在)做屏幕截图,添加到图像中,然后一直这样做,直到最后一个可见单元格+1不存在为止。@NSNoob,在安卓上,你可以得到整个视图,甚至是不可见的部分。我想在中国做同样的事情iOS@Wain,是的,我可以在内存中加载所有内容,它不太有趣,我需要同样的内容Swift@DanieleB您是否看到这些类别的[swift等价物]?()为了这个?它实际上非常有效!!!!我将4个扩展文件复制到我的项目中,然后调用
let image=tableView.screenshot
获取UIImage,然后将其转换为PNG。伟大的图书馆!!!!!我刚刚对答案进行了编辑,以包含新的结果代码