UIPickerView get darker on screenshot

截屏时包含UIPickerview遇到的bug,UIPickerview变黑,闪烁一下就消失了。

答案在这

ios - UIPickerView get darker on screenshot - Stack Overflow

解释在这

ios - drawViewHierarchyInRect:afterScreenUpdates: delays other animations - Stack Overflow

两个方法:

1. UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0);[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];UIImage*im=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();

用GPU绘制,效率更高,但是可能会引起bug

2. UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0);[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage*im=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();

效率低,但是够用,经受过考验的,但是如果有pickerview会出现我的这个bug。


The method drawViewHierarchyInRect:afterScreenUpdates: performs its operations on the GPU as much as possible, and much of this work will probably happen outside of your app’s address space in another process. Passing YES as the afterScreenUpdates: parameter to drawViewHierarchyInRect:afterScreenUpdates: will cause a Core Animation to flush all of its buffers in your task and in the rendering task. As you may imagine, there’s a lot of other internal stuff that goes on in these cases too. Engineering theorizes that it may very well be a bug in this machinery related to the effect you are seeing.

In comparison, the method renderInContext: performs its operations inside of your app’s address space and does not use the GPU based process for performing the work. For the most part, this is a different code path and if it is working for you, then that is a suitable workaround. This route is not as efficient as it does not use the GPU based task. Also, it is not as accurate for screen captures as it may exclude blurs and other Core Animation features that are managed by the GPU task.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 昨天见到我的初恋。 我发现自己还是会不自然。本来很放松的与大家闲扯,突然好像不知道为什么脑袋一片空白了,想不到什么...
    saiyonana阅读 306评论 0 0
  • 比特币是目前为止最成功的区块链应用,是进入区块链世界的入口,也是电子货币金融市场的标杆,如果你想学习区块链技术,比...
    程序员在深圳阅读 1,193评论 0 0
  • 此刻同景,似是归年,昨日犹见,今日如故。曾写简语送旧年,今又提笔落新孤。 单桌独对,笔抵信笺,一份心情,满纸墨迹。...
    文倾阅读 219评论 0 0