search

Home  >  Q&A  >  body text

objective-c - 新手求助:iOS中点击UISlider滑块拖动时数值会跳跃如何解决?

用一个UILabel配合显示UISlider的数值,在IB中拖入一个UILabel和一个UISlider,设置UISlider的最小值是0,最大值是100,当前值是50,continuous属性为YES。在滑动时按住滑块的瞬间滑块会跳跃一小段,而不是从上一次滑块停止的位置开始,请问是什么原因,该如何解决?

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *sliderLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sliderLabel.text = @"50";
}

- (IBAction)sliderChanged:(UISlider *)sender {
    int progress = (int)lroundf(sender.value);
    self.sliderLabel.text = [NSString stringWithFormat:@"%d", progress];
}

@end
ringa_leeringa_lee2771 days ago595

reply all(3)I'll reply

  • 阿神

    阿神2017-04-18 09:20:52

    If possible, it is best to take a screenshot to better observe the phenomenon.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:20:52

    It depends on the number of steps you set

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:20:52

    You are binding the event of the slider. The event must be bound to the team, otherwise problems will occur.

    reply
    0
  • Cancelreply