How to cancel a sequence of UITouch events?

前端 未结 12 2536
悲哀的现实
悲哀的现实 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:27

    On iOS5 there seems to be a private method in UITouch

    -(void)setSentTouchesEnded:(BOOL)ended;
    

    Depending on apple's implementation it could stop sending events

    Another way of doing so would be using associative objects

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if ([(NSNumber *)objc_getAssociatedObject(touch, &outKey) boolValue])
            return;
        if (sometouchisoutsideofview) {
            objc_setAssociatedObject(touch, &outKey, [NSNumber numberWithBool:YES], OBJC_ASSOCIATION_RETAIN);
        }
    }
    

提交回复
热议问题