检索并更改touchUpInside更改为touchUpOutside的点

我已经使UISlider工作就像“滑动解锁”滑块一样。 我需要做的是确定将手指抬起的点被分类为touchUpOUTSIDE而不是touchUpINSIDE 。 这是您将手指滑过滑块末端太远的位置。 我猜这与UIButton相同,你可以按下按钮,然后将手指从按钮上移开,根据你走多远,它仍然可以被归类为touchUpInside 。 如果可能的话,我想用圆圈标记目标区域。

一旦我设法找到这一点,是否有可能改变它? 所以我可以拥有更大的目标区域?

我真的不知道从哪里开始。 谢谢

根据文档,当手指超出控件的边界时,会触发UIControlEventTouchUpOutside事件。 如果您尝试更改该区域,滑块将随之缩放。 为什么不将UIControlEventTouchUpOutside的操作与UIControlEventTouchUpOutside相同?

这花了我几个小时,但我已经设法解决这个问题。 我已经做了很多测试覆盖touchesMoved,touchesEnded和sendAction:action:target:event并且它似乎在70px的帧类中触摸任何触摸INSIDE。 所以对于一个292×52的UISlider来说,从x:-70到x:362或y:-70到122的任何触摸都算作内部触摸,即使它在帧外。

我已经提出了这个代码,它将覆盖一个自定义类,允许框架周围更大的100px区域被视为内部触摸:

 #import "UICustomSlider.h" @implementation UICustomSlider { BOOL callTouchInside; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { callTouchInside = NO; [super touchesMoved:touches withEvent:event]; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint touchLocation = [[touches anyObject] locationInView:self]; if (touchLocation.x > -100 && touchLocation.x < self.bounds.size.width +100 && touchLocation.y > -100 && touchLocation.y < self.bounds.size.height +100) callTouchInside = YES; [super touchesEnded:touches withEvent:event]; } -(void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event { if (action == @selector(sliderTouchOutside)) { // This is the selector used for UIControlEventTouchUpOutside if (callTouchInside == YES) { NSLog(@"Overriding an outside touch to be an inside touch"); [self sendAction:@selector(UnLockIt) to:target forEvent:event]; // This is the selector used for UIControlEventTouchUpInside } else { [super sendAction:action to:target forEvent:event]; } } else { [super sendAction:action to:target forEvent:event]; } } 

稍微调整一点,我也应该能够使用它。 (使用更接近的触摸作为外部触摸)。