找了很久网上文章都是各种复制,而且不管用,最后在stackOverFlow找到怎么解决,记录一下链接
关键是用UILongPressGestureRecognizer,实现拖动和点击
- (void)actionLongGesture:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
CGPoint touchPoint = [sender locationInView:self.progressSlider];
CGFloat value = (self.progressSlider.maximumValue - self.progressSlider.minimumValue) * (touchPoint.x / self.progressSlider.frame.size.width );
NSInteger index = (NSInteger)(value + 0.5);
[self.progressSlider setValue:index animated:NO];
[self valueChange:self.progressSlider];
}else if (sender.state == UIGestureRecognizerStateChanged){
CGPoint touchPoint = [sender locationInView:self.progressSlider];
CGFloat value = (self.progressSlider.maximumValue - self.progressSlider.minimumValue) * (touchPoint.x / self.progressSlider.frame.size.width );
NSInteger index = (NSInteger)(value + 0.5);
[self.progressSlider setValue:index animated:NO];
[self valueChange:self.progressSlider];
}
}
请保持转载后文章内容的完整,以及文章出处。本人保留所有版权相关权利。