(解决方案)
感谢所有回复的人,虽然我自己想出了解决方案,但我将在这里发布解决方案,以防其他人将来需要帮助。
(总百分比和使用百分比默认设置为 100。剩余百分比由百分比使用百分比确定。开始时为 0。)
滑块的初始化包括:
slider1.minimumValue = 0.0;
slider1.maximumValue = [appDelegate getSlider1Percent] + [appDelegate getPercentRemaining];
然后滑块动作: - (IBAction)slider1Action:(UISlider *)sender {
NSUInteger value = sender.value;
self.slider1Counter.text = [NSString stringWithFormat:@"%d%%",value];
NSUInteger currentSlider1Percent = [appDelegate getSlider1Percent];
appDelegate.slider1Percent = value;
if(appDelegate.getSlider1Percent < currentSlider1Percent)
{
nowFree = currentSlider1Percent - value;
appDelegate.percentUsed = [appDelegate getPercentUsed] - nowFree;
appDelegate.percentRemaining = [appDelegate getPercentTotal] - [appDelegate getPercentUsed];
slider2.maximumValue = [appDelegate getSlider2Percent] + appDelegate.getPercentRemaining;
slider3.maximumValue = [appDelegate getSlider3Percent] + appDelegate.getPercentRemaining;
slider4.maximumValue = [appDelegate getSlider4Percent] + appDelegate.getPercentRemaining;
slider5.maximumValue = [appDelegate getSlider5Percent] + appDelegate.getPercentRemaining;
}
else
{
nowFree = value - currentSlider1Percent;
appDelegate.percentUsed = [appDelegate getPercentUsed] + nowFree;
appDelegate.percentRemaining = [appDelegate getPercentTotal] - [appDelegate getPercentUsed];
slider2.maximumValue -= nowFree;
slider3.maximumValue -= nowFree;
slider4.maximumValue -= nowFree;
slider5.maximumValue -= nowFree;
}
}
我希望这可以帮助一些人!
干杯!