Calling layer.setNeedsDisplay() shows a black background

ε祈祈猫儿з 提交于 2019-12-12 19:05:08

问题


When I call setNeedsDisplay() on my UIView's CALayer (either directly, or via needsDisplayOnBoundsChange), it draws the background as black.

myView.layer.setNeedsDisplay()

When I call 'setNeedsDisplay()' on the UIView directly, it doesn't show up as black:

myView.setNeedsDisplay()

Why does this happen, and how can I fix it?


回答1:


The problem was that my view's background color was somehow set to nil instead of .white or .clear, for example.

It seems odd that this happens only when calling it on the layer and not the view.

To reproduce...

This shows up as white:

myView.backgroundColor = nil
myView.setNeedsDisplay()

This causes the view to display as black:

myView.backgroundColor = nil
myView.layer.setNeedsDisplay()


来源:https://stackoverflow.com/questions/43215563/calling-layer-setneedsdisplay-shows-a-black-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!