A count of started touches is not equal to count of finished touches

后端 未结 5 2086
无人共我
无人共我 2021-02-07 10:10

I have the following code for testing purposes:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self customTouchHandler:touches];
}

- (v         


        
5条回答
  •  伪装坚强ぢ
    2021-02-07 10:18

    Cannot comment, so will answer here. You coud print all handlers like this, maybe it helps:

    - (void)customTouchHandler:(NSSet *)touches
    {
        static int handlerCounter = 0;
        handlerCounter++;
        for(UITouch* touch in touches){
            NSLog(@"%d: %d", handlerCounter, touch.phase);
            if(touch.phase == UITouchPhaseBegan)
                touchesStarted++;
            if(touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled)
                touchesFinished++;
        }
        NSLog(@"%d / %d", touchesStarted, touchesFinished);
    }
    

    Is it possible to switch(touch.phase) in obj-c? Is the "or" in the second if evaluated correctly, try using brackts.

提交回复
热议问题