How to cancel a sequence of UITouch events?

前端 未结 12 2540
悲哀的现实
悲哀的现实 2020-12-17 09:43

I have a UIImage view that responds to touch events. I want to cancel the touch sequence, i.e., further calls to touchesMoved:, if the touch goes o

12条回答
  •  盖世英雄少女心
    2020-12-17 10:29

    You need to call [super touchesMoved:withEvent:] in order to let the super view clean up from the event but more importantly, you need to not call [super touchesCancelled:withEvent:].

    Here's what I used on a cell to keep it from getting selected when I detected a swipe:

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (!showingEdit) {
            if (IS_FAR_ENOUGH_TO_BE_A_SWIPE) {
                RESPOND_TO_SWIPE
                showingEdit = YES;
                [super touchesCancelled:touches withEvent:event];
            } else {
                [super touchesMoved:touches withEvent:event];
            }
        }
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (!showingEdit) {
            [super touchesEnded:touches withEvent:event];
        }
    }
    

提交回复
热议问题