Search code examples
ioscocoa-touchtouchesbegan

Animations are preventing touchesBegan


I have this code:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    MainGame *newview = [[MainGame alloc] initWithNibName:@"MainGame" bundle:nil];
    newview.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:newview animated:YES];
}

And it is used to switch to a view called MainGame when I touch the screen however sometimes when I touch the screen nothing happens.

What I'm trying to say is that my touchesBegan is only sometimes receiving the touch, other times it will just be ignored.

Along side this code I also have about 1 - 4 UIView Animations running which are set up by:

[UIView animateWithDuration: ... ];

However if I remove the animations it will always recognize the touchesBegan.

So why are my animations stopping touchesBegan from being recognized and how can I stop this from happening?


Solution

  • Use the UIView method:

    animateWithDuration:delay:options:animations:completion:
    

    and set the options to:

    UIViewAnimationOptionAllowUserInteraction
    

    This should do it for you.