2014-06-23 53 views
-1

我正在實現音頻播放器。但我的滑塊不會拖動。UISlider不會拖動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]]]; 
} 

即使我們拖動它移動到原來的位置滑動滑塊不拖。任何想法,爲什麼滑塊不拖動。

感謝,

+0

任何想法plssss – asifa

回答

0

你好做u盤的UISlidercontinuous屬性YES。這會每次你改變滑塊的值。把這個放到NO會給出發佈的價值。

[mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged]; 

- (IBAction)sliderValueChanged:(UISlider *)sender { 
    NSLog(@"slider value = %f", sender.value); 
} 

你是否處理過滑動事件?

哪裏是這種方法sliderDidEndSliding u的呼喚。