I have an equation to calculate a float value based on the y postion of a UIButton:
float mainVolume = 1 - ((button.y - 126) / 139);
How to i calculate a float value if I have the previous mainVolume float value is already set?
float newButtonYposition = ?
0.568345 = 1 - ((newButtonYposition.y - 126) / 139);
Apply the math rules:
// 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
Calculating the expression produces
newButtonYposition.y = 186
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.