gpt4 book ai didi

IOS SDK - 如何截屏tableView的内容?

转载 作者:技术小花猫 更新时间:2023-10-29 10:51:46 28 4
gpt4 key购买 nike

如何截屏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];
}

关于IOS SDK - 如何截屏tableView的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18590620/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com