我有一个方程式,可根据UIButton的y位置计算浮点值:

float mainVolume = 1 - ((button.y - 126) / 139);

如果我已经设置了先前的主音量浮动值,如何计算浮动值?
float newButtonYposition = ?

0.568345 = 1 - ((newButtonYposition.y - 126) / 139);

最佳答案

应用数学规则:

// Start with this line; rename newButtonYposition.y as X for brevity
0.568345 = 1 - ((X - 126) / 139)
// Subtract one from both sides
0.568345 - 1 = - ((X - 126) / 139)
// Change sign
1 - 0.568345 = (X - 126) / 139
// Multiply by 139
139 * (1 - 0.568345) = X - 126
// Add 126
139 * (1 - 0.568345) + 126 = X


计算表达式produces

newButtonYposition.y = 186

关于ios - 如何基于UIButton的y位置获取未知的浮点值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20523405/

10-11 09:01