【发布时间】:2021-01-24 08:37:30
【问题描述】:
我使用的是 xcode 12。 我编写了扩展 UI 视图如下:
@IBInspectable
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowRadius = newValue
}
}
@IBInspectable
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set {
layer.shadowOpacity = newValue
}
}
@IBInspectable
public var shadowOffset: CGSize {
get {
layer.shadowOffset
}
set {
layer.shadowOffset = newValue
}
}
@IBInspectable
public var shadowColor: UIColor {
get {
return UIColor(cgColor: layer.shadowColor ?? UIColor.clear.cgColor)
}
set {
layer.shadowColor = newValue.cgColor
}
}
一切正常,但是当我调试视图时,我看到了一些像这样的紫色警告。
x-xcode-debug-views://7f8fd2258020?DBGViewDebuggerLaunchSessionParameter=7f8fd2258020: 运行时:优化机会:该层正在使用动态 渲染成本很高的阴影。如果可能尝试设置
shadowPath,或将阴影预渲染成图像并放入 层下。
有人可以向我解释一下并帮助我摆脱它吗?
【问题讨论】:
-
谢谢你的问题,我也有同样的问题,但是我们怎么知道在哪一层工作呢?错误信息中没有任何提示
-
@StackGU 在运行应用程序时,打开调试视图层次结构。在左侧窗格中,您将在有问题的视图(及其父级)旁边看到一个紫色感叹号。
标签: swift xcode debugging uiview