繁体   English   中英

IOS SDK - 如何屏幕查看tableView的镜头内容?

[英]IOS SDK - how to screen shot content of tableView?

如何屏幕截图tableView的所有内容? (所有内容=可见区域+非可见区域)

我试过这个:

UIGraphicsBeginImageContext(self.tableView.bounds.size);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.imageView.image = image1;

但它不起作用,我的意思是它的截图只有可见区域:(


我解决了:))

这是代码:)

+ (UIImage *)captureView:(UIScrollView *)view inContentRect:(CGRect)rect{
    UIImage* image = nil;

    CGPoint savedContentOffset = view.contentOffset;
    CGRect savedFrame = view.frame;

    UIGraphicsBeginImageContextWithOptions(view.contentSize, 1, 0);
    view.contentOffset = CGPointZero;
    view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height);

    [view.layer renderInContext: UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();

    view.contentOffset = savedContentOffset;
    view.frame = savedFrame;

    UIGraphicsEndImageContext();

    // after all of this, crop image to needed size
    return [Utils cropImage:image toRect:rect];                                 
}
+ (UIImage *)captureView:(UIScrollView *)view inContentRect:(CGRect)rect{
    UIImage* image = nil;

    CGPoint savedContentOffset = view.contentOffset;
    CGRect savedFrame = view.frame;

    UIGraphicsBeginImageContextWithOptions(view.contentSize, 1, 0);
    view.contentOffset = CGPointZero;
    view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height);

    [view.layer renderInContext: UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();

    view.contentOffset = savedContentOffset;
    view.frame = savedFrame;

    UIGraphicsEndImageContext();

    // after all of this, crop image to needed size
    return [Utils cropImage:image toRect:rect];                                 
}

您必须使用contentSize.height来获取tableview的高度

试试这个

UIGraphicsBeginImageContext(self.tableView.contentSize.height);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.imageView.image = image1;

是的,你可以这样做。 我不能提供你想要的工作代码,我可以指导你如何做到这一点。 在循环中,您必须通过更改其contentOffset来获取表的所有部分,并将每个图像放在数组中。 获得表视图的所有部分后,必须将表的各个部分连接到一个图像(在cgimagecontext中绘制每个图像,记住为结果图像设置正确的大小)。 就是这样,它不是那么难:)希望这会有所帮助,祝你好运!

暂无
暂无

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

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