简体   繁体   English

CALayer用背景覆盖内容图像

[英]CALayer overwrites contents-image with background

I have a custom UIView with a custom CALayer. 我有一个带有自定义CALayer的自定义UIView。 The Layer overwrites -(void)display; 图层覆盖-(void)显示; to assign a CGImageRef to the layers contents-property. 将CGImageRef分配给图层content-property。 In principle this works as expected(most of the time) but on some devices the view sometimes becomes plain white. 原则上,这可以按预期方式(大部分时间)运行,但在某些设备上,视图有时会变成纯白色。 Actually I can choose the color by setting a backgoundColor. 实际上,我可以通过设置backgoundColor来选择颜色。

Some devices means: out of my 3 test-devices only the iphone5 with iOS7 fails. 某些设备意味着:在我的3个测试设备中,只有带iOS7的iphone5出现故障。 iPhone6+ and iPad both with iOS8 work. 支持iOS8的iPhone6 +和iPad均可使用。

Sometimes means: In principle it works also on the bad devices but there is about a 50-50-chance to get the actual image or plain background... 有时意味着:原则上它也可以在不良设备上工作,但大约有50-50倍的机会可以获取实际图像或纯背景...

(I'm waiting on feedback of some testers to get get better statistics) (我正在等待一些测试人员的反馈,以获得更好的统计信息)

Actually I hope to firgure out what method of the layer or the view(as delegate) I have to overwrite empty to stop this ugly behaviour. 实际上,我希望阐明该层或视图(作为委托)的哪种方法,我必须覆盖空方法才能停止这种丑陋的行为。

Alternatively I will try to add my layer as a sublayer of the normal layer of view. 另外,我将尝试将我的图层添加为普通视图图层的子图层。 But I would like to avoid that because I would end up with 2 layers in the size of the view which is quite large... 但我想避免这种情况,因为最终我会在视图的大小中得到两层,这是相当大的...

Hope some has a hint for me... Thanks in advance 希望有人对我有所提示...预先感谢

Update: it's not restricted to iOS7 I also have a report from an iPad running iOS8.4... 更新:它不仅限于iOS7,我也有运行iOS8.4的iPad的报告...

Update 2: I found out some more. 更新2:我发现了更多。 It looks to me that it's not a problem of the compositing of the layer, but rather one of CGBitmapContext. 在我看来,这不是图层合成的问题,而是CGBitmapContext的问题。
I create a bitmap-context and hold a reference to it in order to render additional parts while keeping some of the old content. 我创建了一个位图上下文并保留对其的引用,以便在保留一些旧内容的同时呈现其他部分。
Afterwards I call CGBitmapContextCreateImage() and set he resulting image as contents of the layer. 之后,我调用CGBitmapContextCreateImage()并将其生成的图像设置为图层的内容。
The image will not contain erverything I have rendered. 该图像将不包含我渲染的所有内容。 For testing I implemented that I can trigger the update of the contents via touch-event: 为了进行测试,我实现了可以通过触摸事件触发内容的更新:

  • if I keep an reference to the image and set the same image again to the contents porperty it shows that the same areas remain white (so actually the layer displays the image correctly) 如果我保留对图像的引用并再次将相同的图像设置为内容属性,则表明相同的区域仍为白色(因此实际上该图层正确显示了图像)
  • if I call CGBitmapContextCreate() again and set the result as content of the layer the image is complete. 如果我再次调用CGBitmapContextCreate()并将结果设置为图层内容,则图像已完成。 There is no change to the bitmap-context in the meantime. 同时,位图上下文没有变化。 That means that 2 consequtive calls to CGBitmapContextCreate() return different images?!? 这意味着对CGBitmapContextCreate()的2次相应调用将返回不同的图像?

    - --

I stopped figuring int out. 我停止弄清楚int了。 I start to to consider it a bug in Core-Graphics/Animation. 我开始认为它是Core-Graphics / Animation中的错误。 Or a abuse by me. 还是我的虐待。 It happens only for quite large views. 它仅在较大的视图中发生。

First attempts with CATiledLayer don#t make me very happy but seem a feasable approach... Or at least a pointer in the direction I will reorganize my code... CATiledLayer的首次尝试并没有使我非常高兴,但似乎是可行的方法……或者至少是一个指向我将重组代码的方向的指针……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM