我有一个 UISlider,我想将 3 个 UILabel 与滑块一起滑到它下面,并更新它们的值,这些值取决于滑块值。拖动滑块时,位置在它应该在的位置和回到中心位置之间来回闪烁。插入断点,在很短的时间内,sliderValueDidChange 方法被多次调用,sliderValue 显示不同的值。有任何想法吗?
- (IBAction)sliderValueDidChange:(UISlider *)sender {
// Update the labels
float sliderValue = sender.value;
percentSplitLabel.text = [NSString stringWithFormat:@"%.0f%@", sliderValue * 100, @"%"];
themSplitValueLabel.text = [NSString stringWithFormat:@"%@%.2f", @"$", totalToBeAddedToTabValue];
meSplitValueLabel.text = [NSString stringWithFormat:@"%@%.2f", @"$", totalBillValue - totalToBeAddedToTabValue];
// Reposition the numbers below
CGRect sliderFrame = splitBillSlider.frame;
percentSplitLabel.center = CGPointMake(sliderFrame.origin.x - sliderFrame.size.width/2.0 + sliderFrame.size.width * sliderValue + 150, percentSplitLabel.center.y);
themSplitValueLabel.center = CGPointMake(percentSplitLabel.center.x + percentSplitLabel.frame.size.width + 10, percentSplitLabel.center.y);
meSplitValueLabel.center = CGPointMake(percentSplitLabel.center.x - percentSplitLabel.frame.size.width, percentSplitLabel.center.y);