当我应用 .drawingGroup() 修改器来提高性能时,为什么我的颜色会发生变化/反转?
看起来它们几乎正在颠倒。 从红变黑
如果我//(不知道术语,散列??)出 .drawingGroup() ,如果不清楚,请在最后查看屏幕截图,否则我不会收到任何错误消息,并且代码会按预期工作。
struct ColorCyclingCircle: View {
var amount = 0.0
var steps = 100
var body: some View {
ZStack {
ForEach(0..<steps) { value in
Circle()
.inset(by: CGFloat(value))
.strokeBorder(LinearGradient(gradient: Gradient(colors: [
self.color(for: value, brightness: 1),
self.color(for: value, brightness: 0.5)
]), startPoint: .top, endPoint: .bottom), lineWidth: 2)
}
}
.drawingGroup()
}
func color(for value: Int, brightness: Double) -> Color {
var targetHue = Double(value) / Double(self.steps) + self.amount
if targetHue > 1 {
targetHue -= 1
}
return Color(hue: targetHue, saturation: 1, brightness: brightness)
}
}
检查您的绘图组使用的色彩空间。或者,您可以将颜色空间传递给绘图组