为什么我在iOS 7上以编程方式创建的屏幕截图看起来如此糟糕? [英] Why does my programmatically created screenshot look so bad on iOS 7?

查看:111
本文介绍了为什么我在iOS 7上以编程方式创建的屏幕截图看起来如此糟糕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与facebook共享应用程序。
我使用此代码截取屏幕截图:

I am trying to implement sharing app with facebook. I used this code to take the screenshot:

CGSize imageSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);
UIGraphicsBeginImageContext(imageSize);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

它在iOS 6上运行良好,但在iOS 7中,图像看起来很糟糕。
我使用了这个答案: iOS:以编程方式制作屏幕截图的最快,最高效的方法是什么?
尝试修复它,它有所帮助,但屏幕截图仍然很糟糕。
屏幕变为另一种颜色,并且所拍摄的图像上没有显示某些对象(如标签)。
任何帮助?

It works great on iOS 6, but in iOS 7 the image looks very bad. I used this answer: iOS: what's the fastest, most performant way to make a screenshot programmatically? for trying to fix it, and it helped, still the screenshot looks bad. The screen gets another color, and some objects (like labels) aren't showing on the image taken. Any help?

----更新----

----Update----

我成功解决了最多的对象,通过改变它们来保留而不是弱。我的主要问题仍然是我的桌面视图,显示为一个大的白色块(它应该是透明的,带有白色文本的标签,所以我们看到的只是白色单元格)。我确实尝试将表格背景定义为clearcolor,没有帮助。

I managed to solve the most objects, by change them to retain instead of weak. My main problem remained my tableview, that shown as a big white block (It supposed to be transparent, with labels with white text, so all we see is white cells). I did try to define the table background as clearcolor,not helps..

----最后更新---

----Last Update---

这里有很棒的答案,并不是真的与我的问题有关..我想让它在iOS7上运行但不使用iOS7 SDK的设备上运行,因为在这一点上需要花费很多精力来切换项目SDK ,当项目快完成时。

There are wonderful answers here that not really regarding to my issue.. I wanted to make it work on device that runs with iOS7 but without using iOS7 SDK, since it takes to much effort to switch the project SDK in this point, when the project is almost done.

无论如何,我添加了最终解决了我的问题的代码的和平:

Anyway, I added the peace of code that finally solved my issue:

此更改只是解决问题:

UIGraphicsBeginImageContextWithOptions(imageSize, NO , 0.0f);

而不是:

UIGraphicsBeginImageContext(imageSize);


推荐答案

API 已添加从iOS 7开始,它应该提供有效的快照获取方式

New API has been added since iOS 7, that should provide efficient way of getting snapshot


  • snapshotViewAfterScreenUpdates:将视图呈现为具有不可修改的内容的UIView

  • snapshotViewAfterScreenUpdates: renders the view into a UIView with unmodifiable content

resizableSnapshotViewFromRect: afterScreenUpdates:withCapInsets :同样的事情,但具有可调整大小的插图

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets : same thing, but with resizable insets

drawViewHierarchyInRect:afterScreenUpdates::同样的事情,如果你也需要绘制所有子视图(比如标签,按钮......)

drawViewHierarchyInRect:afterScreenUpdates: : same thing if you need all subviews to be drawn too (like labels, buttons...)

您可以使用为任何UI效果返回的 UIView ,或者渲染到您需要导出时的图像。

You can use the UIView returned for any UI effect, or render in into an image like you did if you need to export.

我不知道你有多好新方法执行VS你提供的VS(虽然我记得Apple工程师说这个新API效率更高)

I don't know how good this new method performs VS the one you provided (although I remember Apple engineers saying this new API was more efficient)

这篇关于为什么我在iOS 7上以编程方式创建的屏幕截图看起来如此糟糕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆