如何触摸UISlider的UIControlEventValueChanged而不在iOS中触摸UISlider?

时间:2017-01-18 03:27:13

标签: ios uislider

我创建了一个UISlider,如下面的代码:

BrightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(sliderXpoint, 530, sliderwidth, 20)];
BrightnessSlider.minimumValue = 0;
BrightnessSlider.maximumValue = 100;
BrightnessSlider.value = 50;
BrightnessSlider.continuous = YES;
[BrightnessSlider addTarget:self action:@selector(BrightnessSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[BrightnessSlider addTarget:self action:@selector(BrightnessSliderTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];

当我触摸UISlider时会触发以下事件。

- (void)BrightnessSliderValueChanged:(UISlider *)sender {
    BrightnessLabel.text = [NSString stringWithFormat:@"%@%.0f", NSLocalizedString(@"Brightness", @""), sender.value];
}

我想在不触及UISlider的情况下触发UIControlEventValueChanged。 例如,当我将值设置为UISlider时,如下面的代码:

[BrightnessSlider setValue:(BrightnessSlider.value + 1)];

如何触摸UIControlEventValueChanged UISlider UISlider而不触及iOS中的Sources

2 个答案:

答案 0 :(得分:3)

您可以执行以下操作以编程方式触发操作:

[BrightnessSlider sendActionsForControlEvents:UIControlEventValueChanged];

答案 1 :(得分:0)

你可以开火

false

关键是确保你在主线程中。