UIControlEventTouchDragExit triggers when 100 pixels away from UIButton

前端 未结 3 560
无人及你
无人及你 2020-12-03 02:19

At present, the UIControlEventTouchDragExit only triggers when I drag 100 pixels away from the button. I\'d like to customize this behavior and bring that range

3条回答
  •  情话喂你
    2020-12-03 03:02

    Override continueTrackingWithTouch:withEvent: like this to send DragExit/DragOutside events inside of the default gutter:

    - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
    {
        CGFloat boundsExtension = 25.0f;
        CGRect outerBounds = CGRectInset(self.bounds, -1 * boundsExtension, -1 * boundsExtension);
    
        BOOL touchOutside = !CGRectContainsPoint(outerBounds, [touch locationInView:self]);
        if(touchOutside)
        {
            BOOL previousTouchInside = CGRectContainsPoint(outerBounds, [touch previousLocationInView:self]);
            if(previousTouchInside)
            {
                NSLog(@"Sending UIControlEventTouchDragExit");
                [self sendActionsForControlEvents:UIControlEventTouchDragExit];
            }
            else
            {
                NSLog(@"Sending UIControlEventTouchDragOutside");
                [self sendActionsForControlEvents:UIControlEventTouchDragOutside];
            }
        }
        return [super continueTrackingWithTouch:touch withEvent:event];
    }
    

提交回复
热议问题