我有一个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);
最佳答案
如果您在视图中使用自动版式,请尝试将其禁用(文件检查器>取消选中“启用自动版式”)。