美文网首页
UIPickerView get darker on scree

UIPickerView get darker on scree

作者: 23Years | 来源:发表于2016-01-28 15:25 被阅读70次

    截屏时包含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.

    相关文章

      网友评论

          本文标题:UIPickerView get darker on scree

          本文链接:https://www.haomeiwen.com/subject/ghhjkttx.html