gpt4 book ai didi

iOS ScrollView 截图

转载 作者:行者123 更新时间:2023-11-29 11:42:02 30 4
gpt4 key购买 nike

UIImage* image = nil;
UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0);
{
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;

scrollView.contentOffset = CGPointZero;
scrollView.frame= CGRectMake(0, 0, scrollView.contentSize.width,scrollView.contentSize.height);

[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];

image = UIGraphicsGetImageFromCurrentImageContext();

scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();

我无法从 scrollview 获取完整图像,但只有一半,而且一半是黑色

最佳答案

编辑

尝试添加

drawHierarchy(in: self.bounds, afterScreenUpdates: true)

行后

[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];

关于iOS ScrollView 截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45977379/

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