错误与乘数变量有关。为什么它对编译器来说太复杂了?我将如何重写它?我应该发布整个 drawRect 函数吗?
Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
// Progress is a value between 1.0 and -0.5, determined by the current wave idx, which is used to alter the wave's amplitude.
var progress = CGFloat(1.0 - Float(i) / Float(numberOfWaves))
var normedAmplitude = (1.5 * progress - 0.5) * amplitude
var multiplier = CGFloat(min(1.0, (progress / 3.0 * 2.0) + (1.0 / 3.0))) // error point
waveColor.colorWithAlphaComponent(multiplier * CGColorGetAlpha(waveColor.CGColor)).set()
最佳答案
单独计算progress/3.0 * 2.0
即可。
let calc = progress / 3.0 * 2.0
var multiplier = CGFloat(min(1.0, (calc) + (1.0 / 3.0)))
当在一行中计算太多时,可能会发生此错误。
关于swift - 表达式对于编译器来说太复杂了——如何将这个表达式分解成不同的子表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34886176/