我使用PanAesture为我的音频播放器使用AVAudioPlayer制作了自定义滑块。我使用NSTimer来跟踪我的音频的当前时间,在这种情况下,某些时候触摸无法移动Slider。它变得不可拖拽了。之后,如果我尝试或更多时间移动,那么它也可以很好地工作。
编辑:
-(void)setData{
minPoint=totalSeekBar.frame.origin;
maxPoint=CGPointMake(totalSeekBar.frame.size.width+minPoint.x, minPoint.y);
knob.userInteractionEnabled=YES;
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(knobPanned:)];
[knob addGestureRecognizer:panGesture];
[self setSliderForPosition:_currentPosition WithAnimation:YES];
}
-(void)setSliderForPosition:(CGFloat)position WithAnimation:(BOOL)shouldAnimate{
CGFloat totalWidth=totalSeekBar.frame.size.width+totalSeekBar.frame.origin.x;
if(position<_maxValue){
CGFloat newX=(position*totalWidth)/_maxValue;
[self setKnobToPoint:CGPointMake(newX,0) animated:shouldAnimate delegateCall:NO];
}
}
-(void)knobPanned:(UIPanGestureRecognizer*)sender{
[_delegate sliderIsMoving];
_isUpdating=YES;
[self setKnobToPoint:[sender locationInView:self] animated:NO delegateCall:YES];
if(sender.state==UIGestureRecognizerStateEnded){
_currentPosition=[self getNewCurrentValueForPoint:[sender locationInView:self]];
[_delegate sliderDidEndMoving];
}
_isUpdating=NO;
}