objective-cuiviewuitouchtouchesbegantouchesended

touchesEnded called when any part of the screen is tapped with 2 fingers at the same time


I've found this strangest behavior with touch event. The targeting view is not even allocated yet touchesEnded will get called by tapping any part of the screen with 2 fingers not 1, must be 2... then it skips touchesBegan, call touchesEnded. I even checked if the targeted view's userInteraction is set to YES but no, it's set to NO obviously cuz it's NO by default but it's not allocated anyway.

All this does not happen when the targeted view is already allocated and positioned etc.

Has anyone experienced this?? Why does this happen and do I must allocate the property in order to prevent its touch events getting called randomly like crazy? Also why would this strange behavior require 2 fingers at the same time instead of just one tap.... it's not important but I'm just very curious.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *touch = [[event allTouches] anyObject];

if (touch.view == self.buttonStartButton) {

    NSInteger levelUp = [self.levelModel checkForLevelUp];
    if (levelUp == 0) {
        [self byeGameContainer];
    }
    else {
        [self.delegate levelingUp];
    }
}}

Solution

  • So, tried allocating the target and setting its frame out of the screen's bounds didn't work touchesBegan and touchesEnded would STILL get called when any part of the screen is tapped. I even set its userInteractionEnabled = NO but touch events would STILL get called.

    Ended up doing this and this does work. By checking whether the targeted property is allocated or not, touch events finally do not get called when they're not supposed to/shouldn't.

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    

    UITouch *touch = [[event allTouches] anyObject];

    if (touch.view == self.buttonStartButton && self.buttonStartButton != nil) {

    NSInteger levelUp = [self.levelModel checkForLevelUp];
    if (levelUp == 0) {
        [self byeGameContainer];
    }
    else {
        [self.delegate levelingUp];
    }
    

    }}