如何在不打扰用户的情况下保存部分图形上下文?

发布于 2024-09-07 15:00:34 字数 786 浏览 3 评论 0原文

我的情况是这样的,我想以编程方式打印用户可见的当前视图的屏幕并将其保存到相册中。问题是我不希望层次结构中的所有视图都可见。我的计划是:

  1. 制作视图层次结构的副本。
  2. 隐藏不感兴趣的子视图。
  3. 获取打印屏幕。
  4. 将其保存到相册中。

问题是我陷入了第一点。由于 UIView 没有实现 NSCopying 协议,我无法对视图层次结构进行深层复制。我尝试归档和取消归档视图,但这仅在桌面上可用。

据我所知,这里有两个选择:
a) 在所有视图和子视图上实现 NSCopying 协议。 b) 淡出覆盖整个屏幕的白色视图(有点像手动打印屏幕时的闪光效果),在那一刻我隐藏了我想要的视图。

还有其他方法可以解决我错过的这个问题吗?

编辑:

    UIGraphicsBeginImageContext([[wordManager mainWorkViewController] view].frame.size);  
    [[[[wordManager mainWorkViewController] view] layer] renderInContext:UIGraphicsGetCurrentContext()];   
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();

最诚挚的问候 //Abeansits

My situation is like this, I want to programmatically take a print screen of the current view visible to the user and save this to the photo album. The problem is that I don't want all of the views in the hierarchy to be visible. My plan was to:

  1. Make a copy of the view hierarchy.
  2. Hide the subviews which were not interesting.
  3. Take the print screen.
  4. Save it to the photo album.

The problem is that I'm stuck on the first point. Since UIView does not implement the NSCopying protocol I can't make a deep copy of the view hierarchy. I tried archiving and unarchiving the views but this was only available on the dektop.

As I see it there there are two options here:
a) Implement the NSCopying protocol on all the views and subviews.
b) Fade a white view covering the whole screen (sort of like the flash-effect when you take a print screen manually) and in that instant I hide the views I want.

Is there some other way of approaching this problem that I have missed?

Edit:

    UIGraphicsBeginImageContext([[wordManager mainWorkViewController] view].frame.size);  
    [[[[wordManager mainWorkViewController] view] layer] renderInContext:UIGraphicsGetCurrentContext()];   
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();

Best regards
//Abeansits

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2024-09-14 15:00:34

因此,不幸的是没有人能够就此事提供任何帮助。
我如何解决这个问题:

我删除了打印屏幕中不需要的元素。我使用动画来做到这一点,这样就不会出现图形闪烁。最后看起来还不错,可惜我从来没有解决最初的问题。

如果有人发现,请发布修复程序。
最好的问候

//Abeansits

So, unfortunately no one was able to provide any help on this matter.
How I solved the problem:

I removed the elements which I did not want in the print screen. I did this using animations so there would be no graphical flicker. In the end it looked pretty good, to bad I never solved the original problem.

Please post a fix if any one finds one.
Best regards

//Abeansits

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文