Touches Ended not being called

前端 未结 7 1087
無奈伤痛
無奈伤痛 2021-01-17 09:53

I\'ve playing around with recognizing the touches in an iOS Application, and I have this simple code

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent         


        
7条回答
  •  滥情空心
    2021-01-17 10:20

    • Tap gestures (simple, long, 2xshort, 2xfingers tap) do not allow the calls Touches Ended / Canceled if cancelsTouchesInView == NO
    • They allow its calling ONLY IF cancelsTouchesInView property is the default YES
    • Pinch gesture allows all the calls (to Touches Begin / Moved / Ended / Canceled) ONLY IF cancelsTouchesInView property is set to NO
    • If for the pinch gesture the cancelsTouchesInView property would have been YES, touchesMoved would not have been called

    Inside info:

    I am using:

    • 1 finger UITapGestureRecognizer
    • 1 finger UILongPressGestureRecognizer
    • 1 finger double tap UITapGestureRecognizer
    • 2 fingers tap UITapGestureRecognizer
    • 1 UIPinchGestureRecognizer

    And also should receive one finger panning. But what i have found out is that the Pinch gesture was not Ending even if the user had risen one finger. Somehow iOS is still calling the Pinch's selector with "Changed" state.

    My solution was to use the touchesBegin/Moved/Ended to catch the pan and use the number of active touches as safety check in case the pinch selector would be called.

    Other settings i had to use in making the above configuration:

    self.multipleTouchEnabled = YES;
    [oneFingerTapRecognizer requireGestureRecognizerToFail:oneFingerLongPressRecognizer];
    [oneFingerTapRecognizer requireGestureRecognizerToFail:oneFingerDoubleTapRecognizer];
    [oneFingerLongPressRecognizer requireGestureRecognizerToFail:oneFingerDoubleTapRecognizer];
    [twoFingersTapRecognizer requireGestureRecognizerToFail:twoFingersPinch];
    

提交回复
热议问题