调用layer.setNeedsDisplay()显示黑色背景 [英] Calling layer.setNeedsDisplay() shows a black background

查看:102
本文介绍了调用layer.setNeedsDisplay()显示黑色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在UIView的CALayer上调用 setNeedsDisplay()时(直接或通过 needsDisplayOnBoundsChange ),它会绘制背景为黑色。

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

myView.layer.setNeedsDisplay()

当我直接在UIView上调用'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?

推荐答案

问题是我的视图的背景色以某种方式设置为 nil 而不是 .white 或<$例如,c $ c> .clear 。

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.

要重现...

显示为白色:

myView.backgroundColor = nil
myView.setNeedsDisplay()

这会导致视图显示为黑色:

This causes the view to display as black:

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

这篇关于调用layer.setNeedsDisplay()显示黑色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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