UISlider不会拖动iOS

时间:2014-06-23 05:13:01

标签: ios

我正在实施音频播放器。但是我的滑块没有拖动。

·H

@property (strong, nonatomic) IBOutlet UISlider *currentTimeSlider;
@property BOOL scrubbing;

的.m

/*
 * Sets the current value of the slider/scrubber
 * to the audio file when slider/scrubber is used
 */
- (IBAction)setCurrentTime:(id)scrubber {
    //if scrubbing update the timestate, call updateTime faster not to wait a second and dont repeat it

    NSLog(@"%@scrubber",@"drag");

    [NSTimer scheduledTimerWithTimeInterval:0.01
                                     target:self
                                   selector:@selector(updateTime:)
                                   userInfo:nil
                                    repeats:NO];

    [self.audioPlayer setCurrentAudioTime:self.currentTimeSlider.value];
    self.scrubbing = FALSE;
}

/*
 * Sets if the user is scrubbing right now
 * to avoid slider update while dragging the slider
 */
- (IBAction)userIsScrubbing:(id)sender {
    NSLog(@"%@",@"slider drag");

    self.scrubbing = TRUE;
}

/*
 * Updates the time label display and
 * the current value of the slider
 * while audio is playing
 */
- (void)updateTime:(NSTimer *)timer {
    //to don't update every second. When scrubber is mouseDown the the slider will not set
    if (!self.scrubbing) {
        //self.currentTimeSlider.value = [self.audioPlayer getCurrentAudioTime];
    }

      NSLog(self.scrubbing ? @"Yes" : @"No");

    if(self.scrubbing)
    {
        NSLog(@"%@ scrubbing",@"sdfs");
    }
    [self.currentTimeSlider addTarget:self
                  action:@selector(sliderDidEndSliding:)
        forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside)];

    long currentPlaybackTime = [self.audioPlayer getCurrentAudioTime];
    self.currentTimeSlider.value = currentPlaybackTime / [self.audioPlayer getAudioDuration];

    self.timeElapsed.text = [NSString stringWithFormat:@"%@",
                             [self.audioPlayer timeFormat:[self.audioPlayer getCurrentAudioTime]]];

    self.duration.text = [NSString stringWithFormat:@"%@",
                          [self.audioPlayer timeFormat:[self.audioPlayer getAudioDuration] - [self.audioPlayer getCurrentAudioTime]]];
}

即使我们拖动滑块移动到上一个位置,滑块也不会拖动。关于为什么滑块没有拖动的任何想法。

谢谢,

1 个答案:

答案 0 :(得分:0)

您好,我将continuous的{​​{1}}属性设置为UISlider。这将在每次更改滑块值时获得。把它放到YES将给出释放的价值。

NO

您是否处理过幻灯片事件?。

你正在调用此方法[mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged]; - (IBAction)sliderValueChanged:(UISlider *)sender { NSLog(@"slider value = %f", sender.value); }